index.js 519 B

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