Skip to content

Instantly share code, notes, and snippets.

Created November 28, 2017 15:46
Show Gist options
  • Save anonymous/bd1aa962aa2c8fba6528635784dfd5c5 to your computer and use it in GitHub Desktop.
Save anonymous/bd1aa962aa2c8fba6528635784dfd5c5 to your computer and use it in GitHub Desktop.
GraphQL with decorators.
/** Before */
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();
},
},
})
})
/** Now */
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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment