Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created June 23, 2016 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/faca4d41e6821cd9da05ad3dff0c961b to your computer and use it in GitHub Desktop.
Save chuck0523/faca4d41e6821cd9da05ad3dff0c961b to your computer and use it in GitHub Desktop.
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