I'm trying to build a nextjs website using apollo graphql and drupal.
I can get pages, but my request fails when I try to use a search component to query pages i've built.
My query looks like this:
const [loadSearch, {loading, error, fetchMore}] = useLazyQuery(SEARCH, {
notifyOnNetworkStatusChange: true,
onCompleted: (data) => {
console.log(data);
},
onError: (err) => {
console.log(err);
}
});
useEffect(() => {
loadSearch({
variables: {
query: "test"
},
});
}, [search]);
And my query looks like:
export const SEARCH = gql`
query search($query: String!) {
search(query: $query, access: "Search") {
... on SearchDocuments {
total
type
documents {
id
parent {
id
labelOnly
path
title
type
}
path
status
summary
title
type
}
}
}
}
`;
And the error I get in my console is:
Error: GraphQL Request must include at least one of those two parameters: "query" or "queryId"
I can confirm that the query works inside drupal:

Any help is much appreciated
Edit: This error still occurs, even if i've modified to just useQuery instead:
const {loading, error, fetchMore} = useQuery(SEARCH, {
variables: {
query: "test"
},
notifyOnNetworkStatusChange: true,
onCompleted: (data) => {
console.log(data);
console.log('set real data')
},
onError: (err) => {
console.log(err);
console.log('set dummy data');
}
});