File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ** /node_modules /**
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " ab-graphql-1" ,
3+ "version" : " 1.0.0" ,
4+ "scripts" : {
5+ "start" : " nodemon server.js"
6+ },
7+ "keywords" : [
8+ " blogger" ,
9+ " basic"
10+ ],
11+ "author" : " devAbnull" ,
12+ "license" : " ISC" ,
13+ "dependencies" : {
14+ "express-graphql" : " ^0.8.0" ,
15+ "graphql" : " ^14.3.1" ,
16+ "lodash" : " ^4.17.11"
17+ },
18+ "devDependencies" : {
19+ "express" : " ^4.17.1" ,
20+ "nodemon" : " ^1.19.1"
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ const graphql = require ( 'graphql' ) ;
2+ const _ = require ( 'lodash' ) ;
3+
4+ const {
5+ GraphQLObjectType,
6+ GraphQLString,
7+ GraphQLInt,
8+ GraphQLSchema,
9+ } = graphql ;
10+
11+ const users = [
12+ {
13+ id : '12' ,
14+ firstName : 'Alice' ,
15+ age : 22 ,
16+ } ,
17+ {
18+ id : '23' ,
19+ firstName : 'Bob' ,
20+ age : 23 ,
21+ }
22+ ]
23+
24+ const UserType = new GraphQLObjectType ( {
25+ name : 'User' ,
26+ fields : {
27+ id : { type : GraphQLString } ,
28+ firstName : { type : GraphQLString } ,
29+ age : { type : GraphQLInt } ,
30+ }
31+ } ) ;
32+
33+ const RootQuery = new GraphQLObjectType ( {
34+ name : 'RootQueryType' ,
35+ fields : {
36+ userKey : {
37+ type : UserType ,
38+ args : { id : { type : GraphQLString } } ,
39+ resolve ( parentValue , args ) {
40+ return _ . find ( users , { id : args . id } ) ;
41+ }
42+ }
43+ }
44+ } )
45+
46+ module . exports = new GraphQLSchema ( {
47+ query : RootQuery ,
48+ } )
Original file line number Diff line number Diff line change 1+ const express = require ( 'express' ) ;
2+ const app = express ( ) ;
3+ const expressGraphQL = require ( 'express-graphql' ) ;
4+ const schema = require ( './schema' ) ;
5+
6+ const PORT = 9000 ;
7+
8+ app . get ( '/' , ( req , res ) => {
9+ res . send ( 'Hi its working! coool' ) ;
10+ } ) ;
11+
12+ app . use ( '/graphql' , expressGraphQL ( {
13+ graphiql : true ,
14+ schema
15+ } ) ) ;
16+
17+ app . listen ( PORT , ( ) => {
18+ console . log ( `Listening on port http://localhost:${ PORT } /` ) ;
19+ } )
You can’t perform that action at this time.
0 commit comments