Skip to content

Instantly share code, notes, and snippets.

@Mefistophell
Last active September 23, 2018 17:20
Show Gist options
  • Save Mefistophell/a8258da0b51f3b110db35d530d948c4d to your computer and use it in GitHub Desktop.
Save Mefistophell/a8258da0b51f3b110db35d530d948c4d to your computer and use it in GitHub Desktop.
apollo-graphql-api
const { gql } = require('apollo-server-koa')
const UserType = require('./types/user')
const PostType = require('./types/post')
const RootQuery = gql`
type Query {
getUser(id: Int!): User
getPostsByUserId(user_id: Int!): [Post!]
}
`;
const RootMutation = `
type Mutation {
addUser(username: String!, password: String!, fullname: String, email: String, phone: String): String
addPost(user_id: Int!, title: String!, content: String!): String
updatePost(id: Int!, title: String, content: String): Boolean
}
`;
const SchemaDefinition = `
schema {
query: Query
mutation: Mutation
}
`;
module.exports = [
SchemaDefinition, RootQuery, RootMutation, UserType, PostType
];
module.exports = `type Post {
title: String
content: String
}`
module.exports = `type User {
username: String
fullName: String
phone: String
email: String
}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment