eg. I’d like to have an `activityFeed` field on a ...
# orm-help
s
eg. I’d like to have an
activityFeed
field on a
User
, but I want it to return a type that doesn’t exist in the DB, built up of related data from various tables and logic..
n
you'd built a GraphQL Server in front, using prisma-binding and schema stitching
s
Yup, I’ve done that (as in, I have another GraphQL server in front). So do I have to completely re-model the
User
type from scratch?
n
well, you can. not sure what you mean
ah yea you have to redefine the type in your schema
adding new fields and removing fields that you want to hide
then you can implement a field resolver for the new fields
s
Right, gotcha. What about all the resolvers? Same again, redefine them all?
n
yes and no. I recommend studying this example in detail https://github.com/graphcool/graphql-server-example 🙂
s
@nilan so for example
type Experience
is defined in both schemas, because in the Prisma-layer it has a
host: User!
field, but it’s removed in the API-layer.
But the resolver for
reviews: [Review!]!
isn’t defined in the API-layer…?
@nilan So how does it know how to resolve that field? Also, I can’t find an example of a field “addition”, only a removal.
n
So how does it know how to resolve that field
your resolver implementation 🙂
Also, I can’t find an example of a field “addition”, only a removal.
example: https://github.com/prismagraphql/graphql-server-example/blob/master/src/resolvers/Home.ts#L16
s
@nilan That’s what I’m saying, where is the resolver for
reviews
in the example app? There doesn’t seem to be one! So it does it get the one from the generated Prisma code?
n
can you elaborate where you are missing this resolver? I assume you are referring to the
reviews
field on the
Experience
type
here for example https://github.com/prismagraphql/graphql-server-example/blob/master/src/resolvers/Query.ts#L33-L35, the resolution of the incoming query is delegated to the
experiences
query from Prisma.
s
What I mean is that the
Experience
type has been re-defined (not imported) in the API layer, but the resolvers for it don’t seem to have been. In my previous projects, just using Apollo, if a field returns an array of another type, I’d have to tell it how to retrieve that data...
n
yes, you are right. For example, there is no
experiences
query in the application schema.
However, there is a
topExperiences
query, for example.
It looks like you are missing a piece of the puzzle, but it's hard to tell which one 🙂
s
@nilan Ahhhh I’ve got the bit I’m missing. Your queries are adding JOINs aren’t they? Based on the
info
parameter that’s passed through. So in effect when asking for the
reviews
field, you don’t need a resolver because the array and fields are all already there.
n
yup, you can say it like that 🙂
👍 1