gpt4 book ai didi

javascript - react-apollo gql, TypeError : Object(. ..) 不是函数

转载 作者:数据小太阳 更新时间:2023-10-29 04:35:59 32 4
gpt4 key购买 nike

我有一个 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);

我收到以下错误:

About.js:10 Uncaught TypeError: Object(...) is not a function at Object../src/components/About/About.js (About.js:10) at webpack_require (bootstrap 9e0e85e19ef23447e3e2:669) at fn (bootstrap 9e0e85e19ef23447e3e2:87) at Object../src/components/Main/routes.js (routes.js:1) at webpack_require (bootstrap 9e0e85e19ef23447e3e2:669) at fn (bootstrap 9e0e85e19ef23447e3e2:87) at Object../src/components/Main/Main.js (Contact.js:4) at webpack_require (bootstrap 9e0e85e19ef23447e3e2:669) at fn (bootstrap 9e0e85e19ef23447e3e2:87) at Object../src/App.js (zen-observable.js:498) at webpack_require (bootstrap 9e0e85e19ef23447e3e2:669) at fn (bootstrap 9e0e85e19ef23447e3e2:87) at Object../src/index.js (Skills.js:4) at webpack_require (bootstrap 9e0e85e19ef23447e3e2:669) at fn (bootstrap 9e0e85e19ef23447e3e2:87) at Object.0 (styleVariables.js:17) at webpack_require (bootstrap 9e0e85e19ef23447e3e2:669) at bootstrap 9e0e85e19ef23447e3e2:715 at bundle.js:719

这个错误来自哪里,为什么会出现,它是什么意思?它指向我使用 gql

定义查询的行

最佳答案

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

关于javascript - react-apollo gql, TypeError : Object(. ..) 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47367601/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com