How to add fragments #392
-
My I am quite new to the whole stack really: graphql/yoga/prisma and i just came across Pothos last week. My overall needs are quite simple. But i just came across a need where i might have to use I have a:
sort of UI need. The query could be like this:
One of the usecases is a collapsible tree in the UI. I have the relations in place in my Prisma model which obviously has some self-referencing relations for categories. Ive gathered that of course there is no way to get an indefinite depth in my query and it probably might be best to have a hard-limit. Its more or less like the needs expressed here and here. I am ok with having a pre-defined depth. Querying the depths however will mean a very verbose GQL query. I think fragments can help here. I haven't found any mention of fragments in the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Fragments are only used in queries. All spec compliant graphql execution environments should support them. Pothos only generates your graphql schema. How queries are executed (including interpreting fragments) is entirely up to the library that executes the queries in your server. Most JS graphql servers (yoga, apollo, etc) just use the official graphql library for executing queries, and have options for replacing the default execution with graphql-jit. In either case, these fully support fragments. So there is nothing you need to add or change in Pothos, or your server environment to be able to use fragments with your existing graphql schema. A query using a fragment might look something like: query {
sections {
title
categories {
...CategorySelection
categories {
...CategorySelection
categories {
...CategorySelection
categories {
...CategorySelection
}
}
}
}
}
}
fragment CategorySelection on Category {
title
items {
title
}
} |
Beta Was this translation helpful? Give feedback.
Fragments are only used in queries. All spec compliant graphql execution environments should support them. Pothos only generates your graphql schema. How queries are executed (including interpreting fragments) is entirely up to the library that executes the queries in your server.
Most JS graphql servers (yoga, apollo, etc) just use the official graphql library for executing queries, and have options for replacing the default execution with graphql-jit. In either case, these fully support fragments. So there is nothing you need to add or change in Pothos, or your server environment to be able to use fragments with your existing graphql schema.
A query using a fragment might look something…