Skip to content
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

Add source header to API calls #5305

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twenty-apples-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Dashboard now sends source header to API
3 changes: 3 additions & 0 deletions src/components/DevModePanel/DevModePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const DevModePanel: React.FC = () => {
const baseFetcher = createGraphiQLFetcher({
url: process.env.API_URL,
fetch: authorizedFetch,
headers: {
"x-source": "dashboard-plg",
},
});
const fetcher = async (graphQLParams: FetcherParams, opts: FetcherOpts) => {
if (graphQLParams.operationName !== "IntrospectionQuery") {
Expand Down
15 changes: 11 additions & 4 deletions src/graphql/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ import { getApiUrl } from "../config";
import introspectionQueryResultData from "./fragmentTypes.generated";
import { TypedTypePolicies } from "./typePolicies.generated";

const attachVariablesLink = new ApolloLink((operation, forward) =>
forward(operation).map(data => ({
const attachVariablesLink = new ApolloLink((operation, forward) => {
operation.setContext(({ headers = {} }) => ({
headers: {
...headers,
"x-source": "dashboard",
},
}));

return forward(operation).map(data => ({
...data,
extensions: {
...data.extensions,
variables: operation.variables,
},
})),
);
}));
});

export const link = attachVariablesLink.concat(
createUploadLink({
Expand Down
Loading