Skip to content

Commit 3d63545

Browse files
douglasmuraokadavimacedo
authored andcommitted
GraphQL: User sign up required fields (#5743)
1 parent 60d9327 commit 3d63545

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

spec/ParseGraphQLServer.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3110,7 +3110,7 @@ describe('ParseGraphQLServer', () => {
31103110
it('should sign user up', async () => {
31113111
const result = await apolloClient.mutate({
31123112
mutation: gql`
3113-
mutation SignUp($fields: _UserFields) {
3113+
mutation SignUp($fields: _UserSignUpFields) {
31143114
users {
31153115
signUp(fields: $fields) {
31163116
sessionToken

src/GraphQL/loaders/parseClassTypes.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,43 @@ const load = (parseGraphQLSchema, parseClass) => {
551551
});
552552
parseGraphQLSchema.meType = meType;
553553
parseGraphQLSchema.graphQLTypes.push(meType);
554+
555+
const userSignUpInputTypeName = `_UserSignUpFields`;
556+
const userSignUpInputType = new GraphQLInputObjectType({
557+
name: userSignUpInputTypeName,
558+
description: `The ${userSignUpInputTypeName} input type is used in operations that involve inputting objects of ${className} class when signing up.`,
559+
fields: () =>
560+
classCustomFields.reduce(
561+
(fields, field) => {
562+
const type = mapInputType(
563+
parseClass.fields[field].type,
564+
parseClass.fields[field].targetClass,
565+
parseGraphQLSchema.parseClassTypes
566+
);
567+
if (type) {
568+
return {
569+
...fields,
570+
[field]: {
571+
description: `This is the object ${field}.`,
572+
type:
573+
field === 'username' || field === 'password'
574+
? new GraphQLNonNull(type)
575+
: type,
576+
},
577+
};
578+
} else {
579+
return fields;
580+
}
581+
},
582+
{
583+
ACL: defaultGraphQLTypes.ACL_ATT,
584+
}
585+
),
586+
});
587+
parseGraphQLSchema.parseClassTypes[
588+
'_User'
589+
].signUpInputType = userSignUpInputType;
590+
parseGraphQLSchema.graphQLTypes.push(userSignUpInputType);
554591
}
555592
};
556593

src/GraphQL/loaders/usersMutations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const load = parseGraphQLSchema => {
1818
args: {
1919
fields: {
2020
descriptions: 'These are the fields of the user.',
21-
type: parseGraphQLSchema.parseClassTypes['_User'].classGraphQLInputType,
21+
type: parseGraphQLSchema.parseClassTypes['_User'].signUpInputType,
2222
},
2323
},
2424
type: new GraphQLNonNull(defaultGraphQLTypes.SIGN_UP_RESULT),

0 commit comments

Comments
 (0)