Created
June 23, 2016 23:23
-
-
Save chuck0523/faca4d41e6821cd9da05ad3dff0c961b to your computer and use it in GitHub Desktop.
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
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