0

所以我有一个使用GraphQl的 reactjs 应用程序,我试图通过使用 Fragments 来减少重复但是它失败了。

片段(companyQueries.js)

export const CompanyFragment = gql`
  fragment company on WithApiKeys {
    company {
      id
      apiKeys {
        id
        token
        insertedAt
      }
    }
  }
`

开始使用(withCreateApiKeyMutation.js)

import { graphql } from 'react-apollo'
import gql from 'graphql-tag'
import CompanyFragment from '../../../utils/QueryFragments/companyQueries'

console.log(CompanyFragment)
const QUERY = gql`
  query {
    viewer {
      id
      ...company
    }
  }
  ${CompanyFragment}

鉴于这种导出,我希望它至少能够编译,但它会出错。

编译器给出的错误

companyQueries.js的第 3 行出错

TypeError: Object(...) 不是函数

出口 const CompanyFragment = gql <--第 3 行

错误图片

如果有人可以对此提供见解,将不胜感激!

4

1 回答 1

0

I guess you did not import or imported the wrong gql. In the last year the API was changed quite a bit.

You should not import it like

import { gql } from 'react-apollo';

but from this package

import gql from 'graphql-tag';

于 2018-06-06T06:00:56.387 回答