Closed4
nexus / typed-graphql について調べる
nexus + next.jsで最小限
// src/graphql/schema.ts
import { objectType, queryType, mutationType, makeSchema } from '@nexus/schema'
import path from 'path'
const Query = queryType({
definition(t) {
t.string('hello', { resolve: () => 'hello world' })
}
})
export const schema = makeSchema({
types: [Query],
outputs: {
typegen: path.join(process.cwd(), 'generated', 'nexus-typegen.ts'),
schema: path.join(process.cwd(), 'generated', 'schema.graphql')
}
})
// src/pages/api/graphql.ts
import { ApolloServer } from 'apollo-server-micro'
// we'll create these in a second!
import { schema } from './../../graphql/schema'
const apolloServer = new ApolloServer({
schema,
tracing: process.env.NODE_ENV === 'development'
})
export const config = {
api: {
bodyParser: false
}
}
export default apolloServer.createHandler({
path: '/api/graphql'
})
generatedは/api/graphqlPアクセス時に生成される。手動で生成させる場合は
ts-node src/graphql/schema.ts`的なことをやるっぽい
typed-graphql
buildSchema
が走るタイミングでgqlを生成するらしい
このスクラップは2020/12/15にクローズされました