Skip to content

Instantly share code, notes, and snippets.

@timothymiller
Created May 11, 2023 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timothymiller/15f36ce4d378b5c305dbb7eed811e548 to your computer and use it in GitHub Desktop.
Save timothymiller/15f36ce4d378b5c305dbb7eed811e548 to your computer and use it in GitHub Desktop.
Garph (tRPC-like) + Yoga GraphQL Server for Next.js
import { g, InferResolvers, buildSchema } from 'garph'
import { createYoga } from 'graphql-yoga'
const queryType = g.type('Query', {
greet: g
.string()
.args({
name: g.string().optional().default('Max'),
})
.description('Greets a person'),
})
const resolvers: InferResolvers<{ Query: typeof queryType }, {}> = {
Query: {
greet: (parent, args, context, info) => `Hello, ${args.name}`,
},
}
const schema = buildSchema({ g, resolvers })
export const handler = createYoga({
schema,
graphqlEndpoint: '/api/graphql',
landingPage: false,
}).handleRequest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment