harutyunyan29
harutyunyan29

Reputation: 1

Argument of [object Object] passed to parser was not a valid GraphQL DocumentNode. You may need to use 'graphql-tag' or another method to convert

I am getting this error:

"Invariant Violation: Argument of [object Object] passed to parser was not a valid GraphQL DocumentNode. You may need to use 'graphql-tag' or another method to convert your operation into a document"

when I try to use useQuery from @apollo/client

import categoriesQuery from "@/gqlQueries/categories";
import {useQuery} from "@apollo/client";

const CategoryProduct = ({ updateProductCategory }) => {
    const data = useQuery(categoriesQuery)
    //something
}

This is my query and when I use that for example in getStaticProps it works ok

import {gql} from "@apollo/client";

const categoriesQuery = {
    query: gql`
        query {
            mainPage(id:"5wrEkvwy8F87kF5d6WQxCL") {
                featuredCategoriesCollection {
                    items {
                        metaTitle
                        metaDescription
                        title
                        description
                        image {
                            url
                        }
                        bg
                        slug
                    }
                }
            }
        }
    `
};

export default categoriesQuery;

Image of the error

Upvotes: 0

Views: 1472

Answers (1)

jedrzej.kurylo
jedrzej.kurylo

Reputation: 40909

The first argument to useQuery should be the DocumentNode returned by gql.

Therefore, the following will do the trick:

const data = useQuery(categoriesQuery.query)

See the documentation for more details.

Upvotes: 1

Related Questions