Skip to content

GraphQL: Handle required fields from Parse Schema #6271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,44 @@ describe('ParseGraphQLServer', () => {
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 () => {
const schemaController = await parseServer.config.databaseController.loadSchema();

Expand Down
5 changes: 3 additions & 2 deletions src/GraphQL/loaders/parseClassTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ const load = (
[field]: {
description: `This is the object ${field}.`,
type:
className === '_User' &&
(field === 'username' || field === 'password')
(className === '_User' &&
(field === 'username' || field === 'password')) ||
parseClass.fields[field].required
? new GraphQLNonNull(type)
: type,
},
Expand Down