Last active
April 7, 2021 15:01
-
-
Save bloo/8248e471434d68c87f907dca68aaa147 to your computer and use it in GitHub Desktop.
Resilient Tech Blog - Code-first GraphQL with Nexus - typeDefs.ts
This file contains 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
// 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