hi all, my team and i are exploring yoga + prisma ...
# random
c
hi all, my team and i are exploring yoga + prisma and we have a pretty basic question regarding fragments (want to proxy the fragment issued in a mutation direct to apollo to hint at lazy fetching)
so let's say i have something like this:
Copy code
type Person {
    id: ID!
    name: String!
    email: String!
    birthday: String
    phoneNumber: String
}

type User {
    id: ID!
    person: Person!
    isDisabled: Boolean!
}
and i want to proxy to prisma's
createUser
mutation
it takes the data input has an argument for
person
, so i can pass it something like this to create the user and associated person at the same time
Copy code
createUser: (root, { name, email }, { prisma: Prisma }, info) => {
    return prisma.createUser({
        isDisabled: false,
        person: { create: { name, email } }
    });
}
however, the UserPromise that gets returned does not eagerly fetch the user
so if i have a mutation call like this:
Copy code
mutation {
  createUser(
    data: {
    	isDisabled: true,
      person: {
        create: {
          name: "Cedric",
          email: "<mailto:cedric@spantree.net|cedric@spantree.net>"
        }
      }
    }
  ) {
    id
    isDisabled
    person {
      id
      name
      email
    }
  }
}
it errors out bc the user.person returned in the
UserPromise
is null
i see there's a $fragment call i can make to tell prisma to resolve the person or any other related objects
but is there any easy way to just proxy the fragment i received from apollo?
i see that
info.fieldNodes[0].selectionSet.selections
returns an object containing the fields requested
and
$fragment(x)
takes a
DocumentNode
as an argument
but is there a way to translate from one input type to another
just a follow up on this, it looks like prisma binding was what i want for this
Copy code
Mutation: {
        createPerson: (_, { name, email}, { prisma: Prisma }) => prisma.createPerson({name, email}),
        createUser: (_, { name, email }, { binding }, info: GraphQLResolveInfo) => {
            const person = { create: { name, email } };
            const data = { isDisabled: false, person: person };
            return binding.mutation.createUser({data: data}, info);
        }
    }