index.js 596 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'user strict';
  2. const { graphql, buildSchema } = require('graphql');
  3. const schema = buildSchema(`
  4. type Video {
  5. id: ID,
  6. title: String,
  7. duration: Int,
  8. watched: Boolean
  9. }
  10. type Query {
  11. video: Video
  12. }
  13. type Schema {
  14. query: Query
  15. }
  16. `);
  17. const resolvers = {
  18. video: () => ({
  19. id: () => '1',
  20. title: () => 'Foo',
  21. duration: () => 180,
  22. watched: () => true
  23. })
  24. };
  25. const query = `
  26. query myFirstQuery {
  27. video {
  28. id,
  29. title,
  30. duration,
  31. watched
  32. }
  33. }
  34. `;
  35. graphql(schema, query, resolvers)
  36. .then((result) => console.log(result))
  37. .catch((error) => console.log(error));