apollo-client does not work with CORS

后端 未结 4 665
北恋
北恋 2021-02-07 14:44

I am writing a graphql server component on AWS Lambda (NOT using graphql-server). On the client side I\'m using apollo-client. On the response of the lambda function I\'m sett

4条回答
  •  生来不讨喜
    2021-02-07 15:38

    the first, fault we are doing is importing ApolloClient from 'apollo-boost'. Actually we have to import ApolloClient from 'apollo-client'.

    import ApolloClient from 'apollo-client';
    

    Because, ApolloClient from apollo-boost only supports a smaller subset of configuration options. ApolloClient from apollo-client gives you all the configuration options.

    then we can provide link and cache only to Apollo-client instance

    import { InMemoryCache } from "apollo-cache-inmemory";
    import { createHttpLink } from 'apollo-link-http';
    
    const client = new ApolloClient({ 
        link: new createHttpLink(
            {
                uri: "Your QraphQL Link"
            }
        ),
        cache: new InMemoryCache(),
    });
    

提交回复
热议问题