Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import {
// GraphQLのキホン型
GraphQLInt,
GraphQLFloat,
GraphQLString,
GraphQLList,
GraphQLObjectType,
GraphQLEnumType,
// フィールドのRequire化に必要
GraphQLNonNull,
// スキーマ作成に必要
GraphQLSchema,
// GraphQLクエリの実行に必要
graphql
} from 'graphql';
const Query = new GraphQLObjectType({
name: 'RootQueries',
fields: () => ({
echo: {
type: GraphQLString,
args: {
message: {type: GraphQLString}
},
resolve(rootValue, args) {
return `received: ${args.message}`
}
}
})
})
const Schema = new GraphQLSchema({
query: Query
})
let query = `
query getEcho($inputMessage: String) {
receivedMessage: echo(message: $inputMessage)
}
`
// graphql関数はPromiseを返す
graphql(Schema, query, null, null, {inputMessage: "Hello"}).then(function(result) {
console.log(result) // { data: { receivedMessage: 'received: Hello' } }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.