Created
November 28, 2017 15:46
-
-
Save anonymous/bd1aa962aa2c8fba6528635784dfd5c5 to your computer and use it in GitHub Desktop.
GraphQL with decorators.
This file contains 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
/** 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