Skip to content

Commit

Permalink
chore: fix PR 3448
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Kroupa committed Nov 4, 2024
1 parent 708d908 commit 631a878
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .changeset/changelog1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@graphql-yoga/plugin-apollo-usage-report": patch
---

### Fixed
- do not set default values for `clientName` and `clientVersion`
6 changes: 6 additions & 0 deletions .changeset/changelog2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'graphql-yoga': patch
---

### Fixed
- propagation of Yoga `version`
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"apollo"
],
"scripts": {
"build": "pnpm --filter=@graphql-yoga/graphiql run build && pnpm --filter=@graphql-yoga/render-graphiql run build && pnpm --filter=graphql-yoga run generate-graphiql-html&& pnpm --filter=graphql-yoga run inject-version && bob build",
"build": "pnpm --filter=@graphql-yoga/graphiql run build && pnpm --filter=@graphql-yoga/render-graphiql run build && pnpm --filter=graphql-yoga run generate-graphiql-html && bob build && pnpm --filter=graphql-yoga run inject-version",
"build-website": "pnpm build && cd website && pnpm build",
"changeset": "changeset",
"check": "pnpm -r run check",
Expand Down
21 changes: 6 additions & 15 deletions packages/plugins/apollo-usage-report/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ type ApolloUsageReportOptions = ApolloInlineTracePluginOptions & {
/**
* Client name to report to the usage reporting API
*/
clientName?: StringFromRequestFn | string;
clientName?: StringFromRequestFn;
/**
* Client version to report to the usage reporting API
*/
clientVersion?: StringFromRequestFn | string;
clientVersion?: StringFromRequestFn;
};

export interface ApolloUsageReportRequestContext extends ApolloInlineRequestTraceContext {
Expand Down Expand Up @@ -88,23 +88,14 @@ export function useApolloUsageReport(options: ApolloUsageReportOptions = {}): Pl
]),
) as YogaLogger;

let clientNameFactory: StringFromRequestFn = req =>
req.headers.get('apollographql-client-name') || 'graphql-yoga';

if (typeof options.clientName === 'string') {
const clientName = options.clientName;
clientNameFactory = () => clientName;
} else if (typeof options.clientName === 'function') {
let clientNameFactory: StringFromRequestFn = req => req.headers.get('apollographql-client-name');
if (typeof options.clientName === 'function') {
clientNameFactory = options.clientName;
}

let clientVersionFactory: StringFromRequestFn = req =>
req.headers.get('apollographql-client-version') || yoga.version;

if (typeof options.clientVersion === 'string') {
const clientVersion = options.clientVersion;
clientVersionFactory = () => clientVersion;
} else if (typeof options.clientVersion === 'function') {
req.headers.get('apollographql-client-version');
if (typeof options.clientVersion === 'function') {
clientVersionFactory = options.clientVersion;
}

Expand Down

0 comments on commit 631a878

Please sign in to comment.