Is there any update on being able to store Fragments on the Server Side specifically in the Slash? We are building out multiple UI to access the same DB. It would be nice if we didn’t have to redefine the fragments in each UI but rather could just expand fragments that are stored on the server side.
Proposed Schema
type Person {
id: ID
name: String
hasFriends: [Person]
hasAddresses: [Address]
}
type Address {
id: ID
line1: String
city: String
state: String
zip: String
country: String
}
fragment FullAddress on Address {
id
line1
city
state
zip
country
}
fragment AddressAndFriendWithAddress on Person {
hasAddresses {
...FullAddress
}
hasFriends {
id
name
hasAddresses {
...FullAddress
}
}
}
Then I could run a query like:
query {
getPerson(id: ["0x2"]) {
id
name
...AddressAndFriendWithAddress
}
}
Without this, I have to send the fragments on the client side every time which looks like:
query {
getPerson(id: ["0x2"]) {
id
name
...AddressAndFriendWithAddress
}
}
fragment FullAddress on Address {
id
line1
city
state
zip
country
}
fragment AddressAndFriendWithAddress on Person {
hasAddresses {
...FullAddress
}
hasFriends {
id
name
hasAddresses {
...FullAddress
}
}
}
That would be great if everything we are making was javascript, lol. We are making a Swift app, a React app, and a Java/Kotlin app.
For our React app, we are talking right now about either finding a pre-made package to dynamically include fragments or writing our own hook to do so as a useFragment hook to apply to the query before passing it to the useQuery/useMutation hooks.
I does look like a cool idea, but fragments aren’t allowed in the schema itself in GraphQL, just in the operations (the query/mutation requests).
I also wonder how it would work in your clients. For example, I think Apollo Client will need the fragment text on the client side in order to construct the query/mutation in GraphQL anyway. You could try this by removing the fragment defn and seeing what happens in useQuery. I expect it’ll fail. Given that, you still need the text on the client anyway.
I wonder if the simplest answer is a repo of fragments that’s shared across your projects?