1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- 'user strict';
- const { graphql, buildSchema } = require('graphql');
- const schema = buildSchema(`
- type Video {
- id: ID,
- title: String,
- duration: Int,
- watched: Boolean
- }
- type Query {
- video: Video
- }
- type Schema {
- query: Query
- }
- `);
- const resolvers = {
- video: () => ({
- id: () => '1',
- title: () => 'Foo',
- duration: () => 180,
- watched: () => true
- })
- };
- const query = `
- query myFirstQuery {
- video {
- id,
- title,
- duration,
- watched
- }
- }
- `;
- graphql(schema, query, resolvers)
- .then((result) => console.log(result))
- .catch((error) => console.log(error));
|