-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin-ui): Add ApiType to RequestContext
Will be useful in analyzing certain events (such as logins)
- Loading branch information
1 parent
290a576
commit 9b55c17
Showing
11 changed files
with
55 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { GraphQLResolveInfo } from 'graphql'; | ||
|
||
/** | ||
* @description | ||
* Which of the GraphQL APIs the current request came via. | ||
* | ||
* @docsCategory request | ||
*/ | ||
export type ApiType = 'admin' | 'shop'; | ||
|
||
/** | ||
* Inspects the GraphQL "info" resolver argument to determine which API | ||
* the request came through. | ||
*/ | ||
export function getApiType(info: GraphQLResolveInfo): ApiType { | ||
const query = info.schema.getQueryType(); | ||
if (query) { | ||
return !!query.getFields().administrators ? 'admin' : 'shop'; | ||
} | ||
return 'shop'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
import { createParamDecorator } from '@nestjs/common'; | ||
import { GraphQLResolveInfo } from 'graphql'; | ||
|
||
export type ApiType = 'admin' | 'shop'; | ||
import { getApiType } from '../common/get-api-type'; | ||
|
||
/** | ||
* Resolver param decorator which returns which Api the request came though. | ||
* This is useful because sometimes the same resolver will have different behaviour | ||
* depending whether it is being called from the shop API or the admin API. | ||
*/ | ||
export const Api = createParamDecorator((data, [root, args, ctx, info]) => { | ||
const query = (info as GraphQLResolveInfo).schema.getQueryType(); | ||
if (query) { | ||
return !!query.getFields().administrators ? 'admin' : 'shop'; | ||
} | ||
return 'shop'; | ||
return getApiType(info); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters