Created
May 11, 2023 21:41
-
-
Save timothymiller/15f36ce4d378b5c305dbb7eed811e548 to your computer and use it in GitHub Desktop.
Garph (tRPC-like) + Yoga GraphQL Server for Next.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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