Skip to content

Commit

Permalink
Update .changeset/spotty-toes-help.md
Browse files Browse the repository at this point in the history
Co-authored-by: Laurin Quast <[email protected]>
  • Loading branch information
ardatan and n1ru4l committed Jan 2, 2025
1 parent fc18fe7 commit 5af4239
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 63 deletions.
19 changes: 6 additions & 13 deletions .changeset/spotty-toes-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@
'@graphql-hive/yoga': patch
---

Align with GraphQL Yoga >=5.10.4 which has the relevant features mentioned below;

- Remove \`tiny-lru\` dependency, and use `createLruCache` from `graphql-yoga`
- - Yoga already provides a LRU cache implementation, so we can use that instead of having a separate dependency
- Use Explicit Resource Management of GraphQL Yoga plugins for disposal which already respect Node.js process termination
- - The feature has been implemented in `@whatwg-node/server` which is used by GraphQL Yoga. [Learn more about this feature](https://github.com/ardatan/whatwg-node/pull/1830)
- Use \`context.waitUntil\` which is handled by the environment automatically, if not `@whatwg-node/server` already takes care of it with above.
- - The feature has been implemented in `@whatwg-node/server` which is used by GraphQL Yoga. [Learn more about this feature](
https://github.com/ardatan/whatwg-node/pull/1830)
- Respect the given `fetchAPI` by GraphQL Yoga(might be Hive Gateway) for the `fetch` function
- - Hive Gateway uses `fetchAPI` given to GraphQL Yoga for the entire Fetch API implementation, so if Hive Client respects that, we have a control over HTTP calls done internally by the gateway
- Respect Yoga's \`logger\` for logging
- - Similar to above, we want to respect the logger provided by Yoga to have a better control over logging
- Upgrade to `graphql-yoga` >= `5.10.4`
- Improve graceful process termination on Node.js by leveraging `graphql-yoga`'s [dispose lifecycle hooks](https://the-guild.dev/graphql/yoga-server/docs/features/envelop-plugins#ondispose)
- Improve Cloudflare Worker runtime support by registering pending usage reporting requests using the [`waitUntil` API](https://developers.cloudflare.com/workers/runtime-apis/context/#waituntil)
- Use the logger instance from the `graphql-yoga` instance, for a more unified logging experience
- Use the `fetch` API implementation on the `graphql-yoga` instance for HTTP calls
- Replace the internal \`tiny-lru\` dependency with `graphql-yoga`'s internal LRU cache implementation
98 changes: 48 additions & 50 deletions packages/libraries/yoga/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,68 +184,66 @@ export function useHive(clientOrOptions: HiveClient | HivePluginOptions): Plugin
info: (...args) => yoga.logger.info(...args),
},
// Hive Plugin should respect the given FetchAPI, note that this is not `yoga.fetch`
fetch: yoga.fetchAPI.fetch,
fetch: (...args) => yoga.fetchAPI.fetch(...args),
...clientOrOptions.agent,
}
: undefined,
});
void hive.info();
const { experimental__persistedDocuments } = hive;
if (!experimental__persistedDocuments) {
return;
}
addPlugin(
usePersistedOperations({
extractPersistedOperationId(body, request) {
if ('documentId' in body && typeof body.documentId === 'string') {
return body.documentId;
}
if (hive.experimental__persistedDocuments) {
addPlugin(
usePersistedOperations({
extractPersistedOperationId(body, request) {
if ('documentId' in body && typeof body.documentId === 'string') {
return body.documentId;
}

const documentId = new URL(request.url).searchParams.get('documentId');
const documentId = new URL(request.url).searchParams.get('documentId');

if (documentId) {
return documentId;
}
if (documentId) {
return documentId;
}

return null;
},
async getPersistedOperation(key, _request, context) {
const document = await experimental__persistedDocuments.resolve(key);
// after we resolve the document we need to update the cache record to contain the resolved document
if (document) {
const record = contextualCache.get(context);
if (record) {
record.experimental__documentId = key;
record.paramsArgs = {
...record.paramsArgs,
query: document,
};
return null;
},
async getPersistedOperation(key, _request, context) {
const document = await experimental__persistedDocuments.resolve(key);
// after we resolve the document we need to update the cache record to contain the resolved document
if (document) {
const record = contextualCache.get(context);
if (record) {
record.experimental__documentId = key;
record.paramsArgs = {
...record.paramsArgs,
query: document,
};
}
}
}
return document;
},
allowArbitraryOperations(request) {
return experimental__persistedDocuments.allowArbitraryDocuments(request);
},
customErrors: {
keyNotFound() {
return new GraphQLError('Persisted document not found.', {
extensions: { code: 'PERSISTED_DOCUMENT_NOT_FOUND' },
});
return document;
},
notFound() {
return new GraphQLError('Persisted document not found.', {
extensions: { code: 'PERSISTED_DOCUMENT_NOT_FOUND' },
});
allowArbitraryOperations(request) {
return experimental__persistedDocuments.allowArbitraryDocuments(request);
},
persistedQueryOnly() {
return new GraphQLError('No persisted document provided.', {
extensions: { code: 'PERSISTED_DOCUMENT_REQUIRED' },
});
customErrors: {
keyNotFound() {
return new GraphQLError('Persisted document not found.', {
extensions: { code: 'PERSISTED_DOCUMENT_NOT_FOUND' },
});
},
notFound() {
return new GraphQLError('Persisted document not found.', {
extensions: { code: 'PERSISTED_DOCUMENT_NOT_FOUND' },
});
},
persistedQueryOnly() {
return new GraphQLError('No persisted document provided.', {
extensions: { code: 'PERSISTED_DOCUMENT_REQUIRED' },
});
},
},
},
}),
);
}),
);
}
},
onDispose() {
if (hive[autoDisposeSymbol]) {
Expand Down

0 comments on commit 5af4239

Please sign in to comment.