Skip to content

Instantly share code, notes, and snippets.

@haldarmahesh
Last active June 26, 2019 16:16
Show Gist options
  • Save haldarmahesh/da2df518676a67582df65eb47e44c5c0 to your computer and use it in GitHub Desktop.
Save haldarmahesh/da2df518676a67582df65eb47e44c5c0 to your computer and use it in GitHub Desktop.
// src/controller/graphqlController.js
const graphqlHTTP = require('express-graphql');
const { buildSchema } = require('graphql');
// Construct a schema, using GraphQL schema language
const schema = buildSchema(`
type Query {
employee(id: Int!): Employee # `!` signifies this is mandatory
employees: [Employee],
}
type Mutation {
createEmployee(name: String!, department: String!): Employee,
deleteEmployee(id: Int!): DeleteEmployeeResponse
}
input EmployeeInput {
name: String!,
department: String!
}
type DeleteEmployeeResponse {
id: Int!
}
type Employee {
id: Int!,
name: String!,
department: String!
}
`);
// todo -> tie up this schema with GraphQL and the service to call one Query and Mutation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment