0
votes

Im trying out react starter kit and have some confusion with GraphQL and parameters. I just don't know how to pass parameters to the query:

fetch('/graphql', {
            method: 'post',
            headers: {
                Accept: 'application/json',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                query: '{searchquery{title}}',
            })
        });

It's searchquery that should have a string argument somehow.

1
Since you're using React and GraphQL, you may want to give Relay a shot. Relay automatically manages necessary queries and caching of the results. You just need to declare the data requirements, without having to worry about how to construct the query. - Ahmad Ferdous

1 Answers

2
votes

To answer my own question.

fetch('/graphql', {
        method: 'post',
        headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            query: '{searchquery(query:"test"){title}}',
        })
    });