Created
April 11, 2017 08:39
-
-
Save parwatcodes/b3414080e03ff0e68b1227957a9b0d22 to your computer and use it in GitHub Desktop.
passing fakedatabase from rootquery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const graphql = require('graphql'); | |
const fakeDatabase = require('./fakeDatabase'); | |
const newFake = require('./newFake'); | |
const fakeDatabaseType = new graphql.GraphQLObjectType({ | |
name: 'fakeDatabase', | |
fields: { | |
id: { type: graphql.GraphQLID }, | |
name: { type: graphql.GraphQLString }, | |
description: { type: graphql.GraphQLString }, | |
}, | |
}); | |
var schema = {}; | |
schema.getAllUser = new graphql.GraphQLObjectType({ | |
name: 'getAllUser', | |
fields: { | |
data: { | |
type: new graphql.GraphQLList(fakeDatabaseType), | |
resolve: function(obj) { // obj is the parent object containing the data passed from root query resolver | |
return obj; | |
}, | |
} | |
} | |
}) | |
const queryType = new graphql.GraphQLObjectType({ | |
name: 'Query', | |
fields: { | |
getAllUser: { | |
type: schema.getAllUser, | |
args: { | |
}, resolve: function () { | |
return fakeDatabase; // passing the fakedatabase array | |
} | |
} | |
} | |
}); | |
schema.queryTypq1 = new graphql.GraphQLSchema({ query: queryType }); | |
var app = require('express')(); | |
var graphHTTP = require('express-graphql'); | |
app.use('/graphql', graphHTTP({ | |
schema: schema.queryTypq1, | |
graphiql: true | |
})); | |
app.listen(4000, () => { console.log('Server is running on port: 4000'); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment