Does apollo-client work on node.js?

前端 未结 7 1536
醉酒成梦
醉酒成梦 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 09:57

    You can make apollo-client work, but it's not the best option for this use case.

    Try graphql-request instead.

    Minimal GraphQL client supporting Node and browsers for scripts or simple apps

    Features per npmjs:

    • Most simple & lightweight GraphQL client
    • Promise-based API (works with async / await)
    • Typescript support
    • Isomorphic (works with Node / browsers)

    example:

        import { request, gql } from 'graphql-request'
     
        const query = gql`
          {
            Movie(title: "Inception") {
              releaseDate
              actors {
                name
              }
            }
          }
    `
     
    request('https://api.graph.cool/simple/v1/movies', query).then((data) => console.log(data))
    

    I have no affiliation with this package.

提交回复
热议问题