-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: configurable persisted queries with graphql-sse
#3735
Comments
graphql-sse
graphql-sse
graphql-sse
graphql-sse
Here's what I did, it's basically a copy of function subscribe(operation: RequestParameters, variables: Variables) {
return Observable.create<GraphQLResponse>(sink => {
if (!operation.id) {
return sink.error(new Error('Operation id cannot be empty'));
}
return subscriptionsClient.subscribe(
{
query: operation.id,
operationName: operation.name,
variables,
},
sink
);
});
} server: plugins: [
useGraphQLSSE({
extractPersistedOperationId(params) {
return params.query;
},
getPersistedOperation(key) {
// store is the peristed operation json
return store[key];
},
}),
] export function useGraphQLSSE(options = {}) {
const { endpoint = '/graphql/stream', getPersistedOperation, extractPersistedOperationId, ...handlerOptions } = options;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const ctxForReq = new WeakMap();
let handler;
return {
onYogaInit({ yoga }) {
handler = createHandler({
...handlerOptions,
async onSubscribe(req, _params) {
const persistedOperationKey = extractPersistedOperationId(_params);
const persistedQuery = await getPersistedOperation(
persistedOperationKey,
req,
);
const params = {
query: persistedQuery,
operationName: _params.operationName,
variables: _params.variables,
extensions: _params.extensions,
};
const enveloped = yoga.getEnveloped({
...ctxForReq.get(req.raw),
request: req.raw,
params,
});
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
I use persisted queries, but it's not working with
graphql-sse
as it expects aquery
params.Describe the solution you'd like
Add an optional configuration (like the configuration for
usePersistedOperations
) to get the document from the persisted queries json.Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered: