Does apollo-client work on node.js?

前端 未结 7 1528
醉酒成梦
醉酒成梦 2020-12-16 09:34

I need a graphql client lib to run on node.js for some testing and some data mashup - not in a production capacity. I\'m using apollo everywhere else (

相关标签:
7条回答
  • 2020-12-16 10:20

    If someone is looking for a JavaScript version:

    require('dotenv').config();
    const gql = require('graphql-tag');
    const ApolloClient = require('apollo-boost').ApolloClient;
    const fetch = require('cross-fetch/polyfill').fetch;
    const createHttpLink = require('apollo-link-http').createHttpLink;
    const InMemoryCache = require('apollo-cache-inmemory').InMemoryCache;
    const client = new ApolloClient({
        link: createHttpLink({
            uri: process.env.API,
            fetch: fetch
        }),
        cache: new InMemoryCache()
    });
    
    client.mutate({
        mutation: gql`
        mutation popJob {
            popJob {
                id
                type
                param
                status
                progress
                creation_date
                expiration_date
            }
        }
        `,
    }).then(job => {
        console.log(job);
    })
    
    0 讨论(0)
提交回复
热议问题