Alexander Knyazev
Alexander Knyazev

Reputation: 2892

How to make query in Apollo-Client?

Using REST-API, we can make fetch query than make query to server. I use "Apollo-client", but I want to create query witout connecting this query to component. Can I do it? May be I should use methods client.query (http://dev.apollodata.com/core/apollo-client-api.html#ApolloClient.query) and client.mutate or something like this?

Upvotes: 1

Views: 1436

Answers (1)

Alexander Knyazev
Alexander Knyazev

Reputation: 2892

const apolloClient = new ApolloClient({
networkInterface: createNetworkInterface({uri: 'http://localhost:3003/graphql'})
});;

const loginQueruy = gql `Your query code here`,

and then in code

const apolloQuery = {
        query: loginQuery,
    };
apolloClient
        .query(apolloQuery)
        .then((res) => {
            console.log("RES", res)
        })

Upvotes: 5

Related Questions