In one of our project, (node, typescript) we are ...
# orm-help
r
In one of our project, (node, typescript) we are generating the database directly from prisma, and this works great. We would very much like to keep as much of this interface as possible, so that customers can use the same queries and mutations that are exposed directly. We would, however, like to hide a few fields, which will be filled by the node-server. As an minimal example, have a look at the schema below
Copy code
# database-generated input
input TagCreateInput {
  name: String
  description: String
  type: TagTypes
  createdBy: UserCreateOneWithoutCreatedTagsInput!
}

input TagCreateInput {
  name: String
  description: String
  type: TagTypes
}
Now, in this example, the bottom one (publicly exposes) is what the user can see and interact with. Note that we have simply compied that whole
Tag
from the database and removed
createdBy
. This does work, but the maintenance-level is high for this solution, especially as tables evovle with more and more relations, nesting etc. There are so many ways that a
Tag
might be created. I am wondering, is it possible, to instead of copying the whole input-object and removing the fields we don't want publicly available, would it be possible to instead something like extending input with removal of some specific fields? Or is there a different solution available?
m
Hi Rooney. GraphQL inputs and types can’t be extended. You have to copy-paste-modify the input/type in your app schema. Not ideal, but that’s GraphQL for you. If it’s an optional type, you can use a simple resolver that just returns
null
. We do that for some permissioning things where it either returns the actual field or
null
if you don’t have permissions.
You could also have your resolver return
0
or
""
or something else matching the expected type where it’s clear that it’s just “bad data” and the client is expected to interpret that as “dont query this field”
r
Yeah, I agree, that works for queries, but for mutations and its inputs, it it more difficult. I applaud and thank you for the quick reply.