Skip to content

Tris-909/Graph-QL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL

How to set-up a graphqlServer

const express = require('express');
const { graphqlHTTP } = require('graphql-express');
const schema = require('./schema/schema');

app.use('/graphql', graphqlHTTP({
    graphiql: true,
    schema: schema
}));

app.listen(5000);

How to create a GraphQLObjectType :

const graphql = require('graphql');

// UserType
const UserType = new graphql.GraphQLObjectType({
    name: 'UserType',
    description: 'Description for UserType',
    fields: {
        id: {type: graphql.GraphQLID},
        name: {type:  graphql.GraphQLString},
        age: {type: graphql.GraphQLInt},
        job: {type: graphql.GraphQLString}
    }
});

const RootQuery = new graphql.GraphQLObjectType({
    name: 'RootQuery',
    fields: {
        user: {
            type: UserType,
            args: {
                id: {type: graphql.GraphQLID}
            },
            resolve(parent, args) {
                return DummyData.find((id) => id === args.id);
            }
        }
    }
});

// Export schema to app.js file and put it in graphQLHTTP
module.exports = new graphql.GraphQLSchema({
    query: RootQuery
});

About

Learning GraphQL by building a server using NodeJS and Express with GraphQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published