JavaScript Graphql Repo.
This is my simple GraphQL
web-app which has very quite and simple example of graphql user management system. Be like Query
and Mutation
basic operations.
please follow the below instructions:
git clone https://github.com/mbrsagor/graphql.git
cd graphql/server
yarn install
yarn dev
Runs the app in the development mode.
Open http://localhost:4000 to view it in the browser.
cd client
yarn install
yarn start
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
query {
users {
id
name
email
age
}
}
mutation {
createUser(id: 6, name: "Mamun-khan", email: "mamun@gmail.com", age: 29) {
id
name
email
age
}
}
Basically if you want to setup newly I recommend you please follow the below instructions:
yarn init
yarn add --dev graphpack
Then add the code for you project package.json
file.
"scripts": {
"dev": "graphpack",
"build": "graphpack build"
}
N:B: Then continue to the following steps which possesses my project src
directory.
npm install graphql
Then:
var { graphql, buildSchema } = require('graphql');
var schema = buildSchema(`
type Query {
sagor: String
}
`);
var root = { sagor: () => 'Hello Sagor!' };
graphql(schema, '{ sagor }', root).then((response) => {
console.log(response);
});
Frontend
import {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
} from 'graphql';
var schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
hello: {
type: GraphQLString,
resolve() {
return 'world';
},
},
},
}),
});