Name: graphql-remote
Owner: Prisma
Description: null
Created: 2017-12-04 15:05:11.0
Updated: 2018-05-16 09:00:12.0
Pushed: 2018-01-03 15:37:02.0
Homepage: null
Size: 57
Language: TypeScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A toolbelt for creating remote GraphQL schemas with built-in subscriptions and dataloader support.
add graphql-remote
rt { GraphQLServer } from 'graphql-yoga'
rt { fetchTypeDefs, Remote, collectTypeDefs, GraphcoolLink } from 'graphql-remote'
rt * as jwt from 'jsonwebtoken'
c function run() {
nst makeLink = () => new GraphcoolLink(process.env.GRAPHCOOL_SERVICE_ID, process.env.GRAPHCOOL_TOKEN)
nst remoteTypeDefs = await fetchTypeDefs(makeLink())
nst typeDefs = collectTypeDefs(remoteTypeDefs, `
type Query {
me: User
}
type Subscription {
Post: PostSubscriptionPayload
}
type Post {
id: ID!
title: String!
secret: Boolean
extra: String
allPosts: [Post!]!
comments(filter: CommentFilter): [Comment!]
}
input CommentFilter {
text_not: String
}
nst resolvers = {
Query: {
me: (parent, args, ctx, info) => {
const token = ctx.request.get('Authorization').replace('Bearer ', '')
const { userId } = jwt.verify(token, process.env.JWT_SECRET!) as {
userId: string
}
return ctx.remote.delegateQuery('User', { id: userId }, {}, info)
},
},
Post: {
title: (parent) => {
return parent.title + ' - Post Title'
},
extra: () => 'extra field',
allPosts: (_, _2, ctx, info) => {
return ctx.remote.delegateQuery('allPosts', {}, {}, info)
}
},
Subscription: {
Post: {
subscribe: async (parent, args, ctx, info) => {
return ctx.remote.delegateSubscription('Post', args, ctx, info)
},
},
},
nst server = new GraphQLServer({
typeDefs,
resolvers,
context: params => ({ ...params, remote: new Remote(makeLink()) }),
rver.start().then(() => console.log('Server is running on :4000'))
)
graphql-remote
is an extension of the awesome graphql-tools