Giter Site home page Giter Site logo

Apollo Link Support about persistgraphql HOT 11 OPEN

apollographql avatar apollographql commented on September 25, 2024 7
Apollo Link Support

from persistgraphql.

Comments (11)

cooperka avatar cooperka commented on September 25, 2024 3

It seems like this library hasn't been updated since Apollo 2.0 with links. The good news is it's very simple to create a link yourself. All that's needed is the getQueryDocumentKey util.

Here's my working code:

import { ApolloClient } from 'apollo-client';
import { ApolloLink } from 'apollo-link';
import { getQueryDocumentKey } from 'persistgraphql';

import queryMap from './extracted_queries.json';

const persistedQueryLink = new ApolloLink((operation, forward) => {
  const { query, extensions } = operation;

  const queryKey = getQueryDocumentKey(query);
  const persistedQueryId = queryMap[queryKey];

  if (!persistedQueryId) {
    throw new Error('Failed to find query in persisted query map.');
  }

  extensions.persistedQuery = {
    id: persistedQueryId,
  };

  // https://www.apollographql.com/docs/link/links/http.html#persisted-queries
  operation.setContext({
    http: {
      includeExtensions: true,
      includeQuery: false,
    },
  });

  return forward(operation);
});

// Example client creation. You'll probably have other links, too.
const apolloClient = new ApolloClient({ link: persistedQueryLink });

If anyone wants to turn this into a PR here, be my guest.

from persistgraphql.

Poincare avatar Poincare commented on September 25, 2024 2

@mergebandit Unfortunately, I wasn't able to make it to Summit - there is a completed implementation of this link right here.

from persistgraphql.

pleerock avatar pleerock commented on September 25, 2024 2

There is a big lack of docs on how to use persistgraphql with apollo client. I don't know and simply can't find how to connect that ApolloNetworkInterface to my angular app. I guess this issue is related to this problem, so my question is - is it possible to use this library with Apollo client functionality we have up to date?

EDIT: Okay, I found the way, its something like this:

export class AppModule {

    constructor(apollo: Apollo, httpLink: HttpLink) {
        apollo.create({
            link: httpLink.create({ uri: environment.graphServer }),
            cache: new InMemoryCache()
        });
        addPersistedQueries(apollo, outputMap);
    }

}

But now I have different not related to this particular issue because there is no umd bundle for this package.

from persistgraphql.

cocacrave avatar cocacrave commented on September 25, 2024 1

Any update on how to connect with Apollo Link? The comments here are few months old but I don't see any docs

from persistgraphql.

stubailo avatar stubailo commented on September 25, 2024

Yeah definitely this is something we want to do asap, since apollo link is such a natural way to combine stuff.

from persistgraphql.

Poincare avatar Poincare commented on September 25, 2024

Yeah, definitely - this sounds awesome. I'd be happy to help a contributor in case someone's interested in building this?

from persistgraphql.

Poincare avatar Poincare commented on September 25, 2024

Here's what I think the implementation could look like for a PersistLink:

In the request method, we can use the query map produced by persistgraphql in order to look up the ID associated with the query within the Operation, just as we do here. We can then pass along the constructed query to the forward link.

from persistgraphql.

mergebandit avatar mergebandit commented on September 25, 2024

@Poincare any chance you're at the graphql summit? I'd be happy to meet up tomorrow and discuss this fix in person if you are.

from persistgraphql.

mergebandit avatar mergebandit commented on September 25, 2024

The help wanted label is still attached to this issue - do you still want help, or are you good-to-go once that PR gets pushed through?

from persistgraphql.

amityo avatar amityo commented on September 25, 2024

@pleerock does the code work for you? I can see that resolve from query to id works, but QueryManager throws excpetion: query option is required. You must specify your GraphQL document in the query option.

from persistgraphql.

ellioseven avatar ellioseven commented on September 25, 2024

@cooperka

I am wondering how you managed to implement the id via extensions?

I am getting:

GraphQL Request must include at least one of those two parameters: "query" or "queryId"

Which suggests that the extension is not being passed on?

I would greatly appreciate an implementation example .

from persistgraphql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.