我有一个App组件,我正在将其包装到apollo提供程序中:

import React, { Component } from "react";
import { observer, Provider } from "mobx-react";
import { BrowserRouter as Router } from "react-router-dom";
import styled from "styled-components";
import { ThemeProvider } from "styled-components";

// graphQL
import { ApolloClient } from "apollo-client";
import { createHttpLink } from "apollo-link-http";
import { setContext } from "apollo-link-context";
import { InMemoryCache } from "apollo-cache-inmemory";

import Main from "./components/Main/Main";
import Navigation from "./components/Navigation/Navigation";

import { ApolloProvider } from "react-apollo";

const httpLink = createHttpLink({
  uri: "myUri"
});

const authLink = setContext((_, { headers }) => {
  // get the authentication token from local storage if it exists
  const token = "myToken";
  // return the headers to the context so httpLink can read them
  return {
    headers: {
      ...headers,
      authorization: token ? `Bearer ${token}` : null
    }
  };
});

const mozaikClient = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache()
});

@observer
class App extends Component {
  render() {
    return (
      <ThemeProvider theme={theme}>
        <ApolloProvider client={mozaikClient}>
          <Provider {...this.props.stores}>
            <Router>
              <div className="app-container">
                <Navigation />
                <Main />
              </div>
            </Router>
          </Provider>
        </ApolloProvider>
      </ThemeProvider>
    );
  }
}

export default App;

然后,我具有关于组件,该组件要使用提供程序数据:
import React, { Component } from "react";

import { gql, graphql } from "react-apollo";
class About extends Component {
  render() {
    return <div>About component.</div>;
  }
}

const landingPageQuery = gql`
  query landingPage {
    documents(types: [LANDING]) {
      items {
        id
        ... on LandingDocument {
          landingPortrait {
            id
            url
          }
          greeting
          content
        }
      }
    }
  }
`;

export default graphql(landingPageQuery)(About);

我收到以下错误:



该错误来自何处,为什么产生?它是什么意思?它指向我使用gql定义查询的行

最佳答案

这似乎是一个已知问题-请参阅here
尝试安装graphql-tag并从该库中导入gql

09-25 13:45