Graphql 如何在Apollo客户端中进行查询?

Graphql 如何在Apollo客户端中进行查询?,graphql,apollo,react-apollo,Graphql,Apollo,React Apollo,使用REST-API,我们可以进行fetch查询,而不是对服务器进行查询。 我使用“Apollo客户端”,但我想创建查询,而不需要将此查询连接到组件。我能做吗? 也许我应该使用client.query()和client.mutate之类的方法 const apolloClient = new ApolloClient({ networkInterface: createNetworkInterface({uri: 'http://localhost:3003/graphql'}) });; c

使用REST-API,我们可以进行fetch查询,而不是对服务器进行查询。 我使用“Apollo客户端”,但我想创建查询,而不需要将此查询连接到组件。我能做吗? 也许我应该使用client.query()和client.mutate之类的方法

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

const loginQueruy = gql `Your query code here`,
然后是代码

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

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