-
-
Save Axure/aa473345c79d85d00b1335137361b09b to your computer and use it in GitHub Desktop.
GraphQL with decorators.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const rootMutationType = new GraphQLObjectType({ | |
| name: 'MutationRoot', | |
| fields: () => ({ | |
| addWord1: { | |
| args: { | |
| value: { | |
| name: 'value', | |
| type: new GraphQLNonNull(GraphQLString), | |
| }, | |
| }, | |
| type: wordType, | |
| async resolve(obj: any, {value}: { | |
| value: string; | |
| }, context: any) { | |
| const newWord = new Word(); | |
| newWord.value = value; | |
| return await newWord.save(); | |
| }, | |
| }, | |
| }) | |
| }) | |
| export const rootQueryType = new GraphQLObjectType({ | |
| name: 'RootQueryType', | |
| fields: { | |
| hello: { | |
| type: GraphQLString, | |
| args: { | |
| value: { | |
| name: 'value', | |
| type: GraphQLString, | |
| }, | |
| }, | |
| resolve() { | |
| return 'world'; | |
| }, | |
| }, | |
| shit: { | |
| type: new GraphQLObjectType({ | |
| name: 'shit', | |
| fields: { | |
| shit: { | |
| type: GraphQLString, | |
| args: { | |
| name: { | |
| name: 'name', | |
| type: GraphQLString | |
| } | |
| }, | |
| resolve(obj: any, {name}: any, context: any) { | |
| return obj.shit + context.msg + ', name:' + name; | |
| }, | |
| }, | |
| }, | |
| }), | |
| resolve(obj: any, {}, context: any) { | |
| context.msg = '_context'; | |
| return { | |
| shit: 'shit', | |
| }; | |
| }, | |
| }, | |
| }, | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TestRootMutations { | |
| @GraphQLRootMutationField(wordType, { | |
| value: { | |
| name: 'value', | |
| type: new GraphQLNonNull(GraphQLString), | |
| }, | |
| }) | |
| async addWord1(obj: any, {value}: { | |
| value: string; | |
| }, context: any) { | |
| const newWord = new Word(); | |
| newWord.value = value; | |
| return await newWord.save(); | |
| } | |
| } | |
| @GraphQLObjectDefinition | |
| class ShitQuery implements GraphQLQueryDescriptionInterface<ShitQueryInterface, ShitQuery> { | |
| @GraphQLQueryField(GraphQLString, { | |
| name: { | |
| name: 'name', | |
| type: GraphQLString | |
| } | |
| }) | |
| shit(obj: any, params: { name: string }, context: any): string { | |
| return obj.shit + context.msg + ', name:' + params.name; | |
| } | |
| } | |
| @GraphQLRootQuery | |
| class ShitRootQuery { | |
| @GraphQLRootQueryField(GraphQLString, { | |
| value: { | |
| type: GraphQLString, | |
| } | |
| }) | |
| hello(obj: any, params: { | |
| value: string; | |
| }, context: any): string { | |
| return 'world!' + params.value; | |
| } | |
| @GraphQLRootQueryLazyField(() => ShitQuery) | |
| shit(obj: any, params: any, context: any): ShitQueryInterface { | |
| context.msg = '_context'; | |
| return { | |
| shit: 'shit' | |
| }; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| query { | |
| getWordWithExplanations(word: "shit") { | |
| value, wordExplanations { | |
| id, word { | |
| value, wordExplanations { | |
| content, word { | |
| wordExplanations { | |
| content, word { | |
| wordExplanations { | |
| word { | |
| value | |
| createdAt | |
| updatedAt | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment