Dan Ramos
03/02/2019, 12:03 AMexport const User = prismaObjectType({
name: "User",
definition(t) {
t.prismaFields(["id", "email", "first_name", "last_name", "address"]);
}
});
This works fine except 'address' is returning as null. Address is a nested object type so I'm not sure how/why that's causing issues. Can anyone help?Jorge
03/02/2019, 12:49 AMDan Ramos
03/02/2019, 12:53 AMJorge
03/02/2019, 1:36 AMJorge
03/02/2019, 1:36 AMJenkins
03/02/2019, 11:30 AMDan Ramos
03/02/2019, 5:46 PMJenkins
03/02/2019, 5:52 PMDan Ramos
03/02/2019, 5:52 PMJenkins
03/02/2019, 5:55 PMaddress
a field in your datamodel.prisma
?Jenkins
03/02/2019, 6:04 PMaddress
as a 'computed field' in your GraphQL Schema.
That resolver would look something like:
Assume ctx: { dbp: PrismaClient, dbm: MySQLClient }
export const User = prismaObjectType({
name: "User",
definition(t) {
t.prismaFields(["id", "email", "first_name", "last_name"]);
t.field({
name: 'address',
type: 'Address', // You have to define this somewhere and add it to the types array during `makeSchema`
resolve: (parent, args, ctx) => ctx.dbm.addressByUserId({ id: parent.id })
});
}
});
Or something along those lines. Not 100% sure as I'm still fairly new to Nexus (but loving it so far).Dan Ramos
03/02/2019, 6:23 PMJenkins
03/02/2019, 6:29 PMJenkins
03/02/2019, 6:29 PMDan Ramos
03/02/2019, 6:30 PMJenkins
03/02/2019, 6:31 PMJenkins
03/02/2019, 6:32 PMJenkins
03/02/2019, 6:32 PMJenkins
03/02/2019, 6:34 PMDan Ramos
03/02/2019, 6:48 PMJenkins
03/02/2019, 6:50 PMDan Ramos
03/02/2019, 6:58 PM