Comments (11)
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.
@mergebandit Unfortunately, I wasn't able to make it to Summit - there is a completed implementation of this link right here.
from persistgraphql.
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.
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.
Yeah definitely this is something we want to do asap, since apollo link is such a natural way to combine stuff.
from persistgraphql.
Yeah, definitely - this sounds awesome. I'd be happy to help a contributor in case someone's interested in building this?
from persistgraphql.
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.
@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.
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.
@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.
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)
- Maximum call stack error when using cloneDeep in query transformer
- [Idea] replace json property names with ordinals to reduce bandwidth HOT 4
- Must provide a query error when use with graphql-subscription
- Mixing .graphql files with tagged template literals HOT 1
- Server and client sync
- Can it be used with Relay Modern? HOT 2
- can't install on Windows HOT 2
- [BUG] persistgraphql serializes *differently* from apollo client, breaking the whitelist HOT 1
- Register query manually
- Support glob syntax [feature request]
- [BUG] template strings within attributes not parsed correctly
- How should we namespace open source queryTransformers? HOT 7
- Hapi17 Example
- Relax dependency requirements HOT 5
- Does not recognize .gql file extension HOT 1
- Commented out query causes syntax error during javascript extraction
- Queries from both external graphql files and JS extraction aren't output together
- This tool can only generate 1 query when scan a directory that contains multiple ".graphql" files HOT 2
- Add / enable Travis CI
- Support babel compiled AST.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from persistgraphql.