I've a Next.js project using the Apollo GraphQL client 3.7.17, where the following code works for me:
const { loading, data, error } = useQuery(gql`
query GetTeamCurrentWeek($teamId: ID!) {
team(id: $teamId, idType: DATABASE_ID) {
teamMeta {
currentweek
}
}
}
`,
{
variables: {
teamId: 715
}
}
);
If however I change the query to use fragments, I get data 'undefined':
fragment teamCurrentWeek on RootQuery {
team(id: $teamId, idType: DATABASE_ID) {
teamMeta {
currentweek
}
}
}
query GetTeamCurrentWeek($teamId: ID!) {
...teamCurrentWeek
}
I'm querying Wordpress using GraphQL and if I put the same query using fragments into the GraphiQL IDE, it works as expected and returns the same data as the non-fragments one, so it looks like the syntax/underlying data structure is all correct.
What is it about how I'm using it here that stops the query with fragments working?