Skip to content

Instantly share code, notes, and snippets.

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 bloo/8248e471434d68c87f907dca68aaa147 to your computer and use it in GitHub Desktop.
Save bloo/8248e471434d68c87f907dca68aaa147 to your computer and use it in GitHub Desktop.
Resilient Tech Blog - Code-first GraphQL with Nexus - typeDefs.ts
// typeDefs.ts
import { objectType, extendType, enumType } from 'nexus'
import { NonprofitType } from '@prisma/client'
const NONPROFIT = 'Nonprofit'
const BUDGET = 'Budget'
const NONPROFIT_TYPE = 'NonprofitType'
export const nonprofit = objectType({
name: NONPROFIT,
definition(t) {
t.string('id')
t.string('name')
t.field('type', {
type: NONPROFIT_TYPE,
})
t.list.field('budget', {
type: BUDGET,
})
},
})
export const nonprofitType = enumType({
name: NONPROFIT_TYPE,
members: NonprofitType,
})
export const budget = objectType({
name: BUDGET,
definition(t) {
t.string('id')
t.string('name')
t.int('amount')
t.date('fiscalYearStart') // date is a custom scalar type
t.date('fiscalYearEnd') // date is a custom scalar type
},
})
export const nonprofitQuery = extendType({
type: 'Query',
definition: (t) =>
t.field('getAllNonprofit', {
type: NONPROFIT,
list: true,
resolve: (_source, args, context, info) => {
// do stuff
return context.db.nonprofit.findMany()
},
}),
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment