Closed billdami closed 2 years ago
Hi @billdami. Yes, fragments are supported. However, you need to inline them with the query. Here is how that would look like:
export const MY_FRAGMENT = gql`
fragment MyFragment on User {
id
dateCreated
name
}
`;
export const GET_USERS = gql`
query GetUsers($filters: UserFilters!) {
users(filters: $filters) {
...MyFragment
}
}
${MY_FRAGMENT}
`;
export const GET_USER = gql`
query GetUser($id: Int!) {
user(id: $id) {
...MyFragment
someOtherField
}
}
${MY_FRAGMENT}
`;
I hope this solves your issue.
makes sense, thank you!
Are graphql fragments supported out-of-the-box in glimmer-apollo? I tried creating one with an inline
gql
tag and using it in queries, however when the graphql request is called, the fragment is not expanded, so the query sent to the server contains the...MyFragment
line, instead of the fields it contains, and I get anUnknown fragment
error back from the server.For example:
^ Should that work?