Handle required fields (#6271)
This commit is contained in:
committed by
Antonio Davi Macedo Coelho de Castro
parent
4f1d3b0654
commit
e0e06ef131
@@ -1850,6 +1850,44 @@ describe('ParseGraphQLServer', () => {
|
|||||||
expect(updatedSuperCar).toBeTruthy();
|
expect(updatedSuperCar).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle required fields from the Parse class', async () => {
|
||||||
|
const schemaController = await parseServer.config.databaseController.loadSchema();
|
||||||
|
await schemaController.addClassIfNotExists('SuperCar', {
|
||||||
|
engine: { type: 'String', required: true },
|
||||||
|
doors: { type: 'Number', required: true },
|
||||||
|
price: { type: 'String' },
|
||||||
|
mileage: { type: 'Number' },
|
||||||
|
});
|
||||||
|
|
||||||
|
await resetGraphQLCache();
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: { __type },
|
||||||
|
} = await apolloClient.query({
|
||||||
|
query: gql`
|
||||||
|
query requiredFields {
|
||||||
|
__type(name: "CreateSuperCarFieldsInput") {
|
||||||
|
inputFields {
|
||||||
|
name
|
||||||
|
type {
|
||||||
|
kind
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
__type.inputFields.find(o => o.name === 'price').type.kind
|
||||||
|
).toEqual('SCALAR');
|
||||||
|
expect(
|
||||||
|
__type.inputFields.find(o => o.name === 'engine').type.kind
|
||||||
|
).toEqual('NON_NULL');
|
||||||
|
expect(
|
||||||
|
__type.inputFields.find(o => o.name === 'doors').type.kind
|
||||||
|
).toEqual('NON_NULL');
|
||||||
|
});
|
||||||
|
|
||||||
it('should only allow the supplied output fields for a class', async () => {
|
it('should only allow the supplied output fields for a class', async () => {
|
||||||
const schemaController = await parseServer.config.databaseController.loadSchema();
|
const schemaController = await parseServer.config.databaseController.loadSchema();
|
||||||
|
|
||||||
|
|||||||
@@ -159,8 +159,9 @@ const load = (
|
|||||||
[field]: {
|
[field]: {
|
||||||
description: `This is the object ${field}.`,
|
description: `This is the object ${field}.`,
|
||||||
type:
|
type:
|
||||||
className === '_User' &&
|
(className === '_User' &&
|
||||||
(field === 'username' || field === 'password')
|
(field === 'username' || field === 'password')) ||
|
||||||
|
parseClass.fields[field].required
|
||||||
? new GraphQLNonNull(type)
|
? new GraphQLNonNull(type)
|
||||||
: type,
|
: type,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user