@basementscripts/graphql-schema-builder
v1.1.1
Published
GraphQL Schema Builder for Node.js
Downloads
33
Keywords
Readme
@basementscripts/graphql-schema-builder
Implement Schema in ApolloServer instance
import { ApolloServer, ApolloServerExpressConfig } from 'apollo-server-express'
import { SchemaBuilder } from '@basementscripts/graphql-schema-builder'
import { base, input, filter } from '@basementscripts/graphql-schema-builder/typeDefs'
import { UserTypeDefs, UserResolver} from '@user-service/graphql'
const builder = new SchemaBuilder({
typeDefs: [base, input, filter, UserTypeDefs],
resolvers: [UserResolver]
})
const server = new ApolloServer({
schema: builder.toSchema(),
//...config
})
Resolver
import { field, fields, mutation, query, resolver } from '@basementscripts/graphql-schema-builder/decorators'
@resolver()
export default class AuthRoleResolver extends Resolver {
@fields('account')
User
@query()
getUser(root, input): GraphQLResponse<any> {
return input
}
@mutation()
createUser(root, { input }: any): GraphQLResponse<any> {
return input
}
@field('user')
sideEffectUser({ user }) {
return user
}
@field('users')
sideEffectUsers({ users }) {
return users
}
}