Skip to content

Commit

Permalink
Merge pull request #396 from thefrontside/dl/auth-entities
Browse files Browse the repository at this point in the history
Pass Backstage Auth token to `catalog.queryEntities`
  • Loading branch information
wKich authored Mar 27, 2024
2 parents 1cf8870 + f55145f commit 76a62e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-taxis-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@frontside/backstage-plugin-graphql-backend-module-catalog': patch
---

Pass Backstage Auth token to `catalog.queryEntities`
8 changes: 6 additions & 2 deletions plugins/graphql-backend-module-catalog/src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import _ from 'lodash';
import { encodeId } from '@frontside/hydraphql';
import { Resolvers } from 'graphql-modules';
import { CATALOG_SOURCE } from './constants';
import { getBearerTokenFromAuthorizationHeader } from '@backstage/plugin-auth-node';
import { stringifyEntityRef } from '@backstage/catalog-model';
import { CatalogApi } from '@backstage/catalog-client';
import { Connection } from 'graphql-relay';
import type { Request } from 'node-fetch';
import { encodeEntityId } from './helpers';
import { getDirective } from '@graphql-tools/utils';
import {
Expand Down Expand Up @@ -377,7 +379,7 @@ export const queryResolvers: () => Resolvers = () => {
fullTextFilter?: { term: string; fields?: string[] };
};
} = {},
{ catalog }: { catalog: CatalogApi },
{ catalog, request }: { catalog: CatalogApi, request?: Request },
{ schema }: { schema: GraphQLSchema },
): Promise<Connection<{ id: string }>> => {
if (filter && rawFilter) {
Expand All @@ -386,6 +388,8 @@ export const queryResolvers: () => Resolvers = () => {
);
}

const token = getBearerTokenFromAuthorizationHeader(request?.headers.get('authorization'));

if (!fieldMap) {
fieldMap = traverseFieldDirectives(
schema.getType('Entity') as GraphQLCompositeType,
Expand Down Expand Up @@ -491,7 +495,7 @@ export const queryResolvers: () => Resolvers = () => {
],
cursor,
limit,
});
}, { token });

// TODO Reuse field's resolvers https://github.com/thefrontside/HydraphQL/pull/22
return {
Expand Down

0 comments on commit 76a62e5

Please sign in to comment.