From 03caf88ea1125df3330ef66049bccfd0278a744c Mon Sep 17 00:00:00 2001 From: Suyash Das <71306286+suyashdas@users.noreply.github.com> Date: Sat, 12 Apr 2025 06:52:03 +0530 Subject: [PATCH 1/2] Imported GraphQLString and fixed the resolver part as per code first approach. --- .../running-an-express-graphql-server.mdx | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/website/pages/docs/running-an-express-graphql-server.mdx b/website/pages/docs/running-an-express-graphql-server.mdx index e01dabb922..7129323fae 100644 --- a/website/pages/docs/running-an-express-graphql-server.mdx +++ b/website/pages/docs/running-an-express-graphql-server.mdx @@ -49,35 +49,30 @@ console.log('Running a GraphQL API server at http://localhost:4000/graphql'); ```javascript -const { GraphQLObjectType, GraphQLSchema } = require('graphql'); +const { GraphQLObjectType, GraphQLSchema, GraphQLString } = require('graphql'); const { createHandler } = require('graphql-http/lib/use/express'); const express = require('express'); - -// Construct a schema + +// Construct a schema and resolver const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'Query', fields: { - hello: { type: GraphQLString }, + hello: { + type: GraphQLString, + resolve: () => 'Hello world!' + }, }, }), }); - -// The root provides a resolver function for each API endpoint -const root = { - hello() { - return 'Hello world!'; - }, -}; - + const app = express(); - + // Create and use the GraphQL handler. app.all( '/graphql', createHandler({ - schema: schema, - rootValue: root, + schema: schema }), ); From 86899be88a67884162b7617378ef2850b02c0daf Mon Sep 17 00:00:00 2001 From: Suyash Das <71306286+suyashdas@users.noreply.github.com> Date: Sat, 12 Apr 2025 11:51:07 +0530 Subject: [PATCH 2/2] Imported GraphQLString and fixed the error. --- .../running-an-express-graphql-server.mdx | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/website/pages/docs/running-an-express-graphql-server.mdx b/website/pages/docs/running-an-express-graphql-server.mdx index 7129323fae..2b64f1e20c 100644 --- a/website/pages/docs/running-an-express-graphql-server.mdx +++ b/website/pages/docs/running-an-express-graphql-server.mdx @@ -52,27 +52,32 @@ console.log('Running a GraphQL API server at http://localhost:4000/graphql'); const { GraphQLObjectType, GraphQLSchema, GraphQLString } = require('graphql'); const { createHandler } = require('graphql-http/lib/use/express'); const express = require('express'); - -// Construct a schema and resolver + +// Construct a schema const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'Query', fields: { - hello: { - type: GraphQLString, - resolve: () => 'Hello world!' - }, + hello: { type: GraphQLString }, }, }), }); - + +// The root provides a resolver function for each API endpoint +const root = { + hello() { + return 'Hello world!'; + }, +}; + const app = express(); - + // Create and use the GraphQL handler. app.all( '/graphql', createHandler({ - schema: schema + schema: schema, + rootValue: root, }), );