Closed friebetill closed 4 years ago
I am not sure I understand your issue but it seems that you want to have graphql field latestStory
that does not exist in your datamodel / database.
You don't need to define latestStory
in your prisma schema. Just add resolver to your graphql server that will use stories
from your database.
I don't know how you are building your graphql schema (nexus maybe?), so I cannot help further.
I am not sure I understand your issue but it seems that you want to have graphql field latestStory that does not exist in your datamodel / database.
Yes exactly, I want to have a GraphQL Field that does not exist in the database.
You don't need to define latestStory in your prisma schema. Just add resolver to your graphql server that will use stories from your database.
I tried your suggestion that I only define the resolver and have latestStory
not in the schema, but unfortunately I get the following error message when trying to start the server:
[ERROR] 11:30:48 Error: User.latestStory defined in resolvers, but not in schema
I don't know how you are building your graphql schema (nexus maybe?), so I cannot help further.
To generate the schema I use prisma generate
and graphqlgen
with
Prisma CLI version: prisma/1.34.0 (darwin-x64) node-v13.8.0
graphqlgen 0.6.0-rc9
I guess the software is outdated by now. Unfortunately there are so many systems (Prisma, graphqlgen, prisma2, graphcool, nexus, ...) that I lost the overview and have no idea what I should use by now. I hope Prisma 2 will make things clearer.
If you can give me a suggestion which tools support this feature, I would be very happy to update my software.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.
Problem
It is not possible to create a computed field with complex data. With native data types it is no problem, but with complex data types, Prisma says that there must be a relation.
In this example, Prisma complains that
latestStory
is not possible because the relation is missing. This is problematic for me, because at the beginning of my project, eachUser
could only have oneStory
, but I later changed that so that oneUser
can have multipleStories
. But now I still have clients that expect oneStory
. So for backwards compatibility I have to keep it.To avoid duplication in the database schema, I would not like to add another relation between
User
andStory
.Solution
A solution could be to have computed fields with complex data types. Then one can define in the resolver how the complex data type should be computed.
For example, it could look like this in Prisma:
or