@envelop/generic-auth
Advanced tools
Comparing version
@@ -125,13 +125,2 @@ "use strict"; | ||
function AuthorizationExtendedValidationRule(context, args) { | ||
const operations = {}; | ||
const fragments = {}; | ||
for (const definition of args.document.definitions) { | ||
if (definition.kind === 'OperationDefinition') { | ||
operations[definition.name?.value ?? args.operationName ?? 'Anonymous'] = | ||
definition; | ||
} | ||
else if (definition.kind === 'FragmentDefinition') { | ||
fragments[definition.name.value] = definition; | ||
} | ||
} | ||
const user = args.contextValue[contextFieldName]; | ||
@@ -158,6 +147,29 @@ const handleField = ({ node: fieldNode, path, }, parentType) => { | ||
let curr = args.document; | ||
const operationAST = (0, graphql_1.getOperationAST)(args.document, args.operationName); | ||
const operationType = operationAST?.operation ?? 'query'; | ||
let currType = (0, utils_1.getDefinedRootType)(schema, operationType); | ||
for (const pathItem of path) { | ||
curr = curr[pathItem]; | ||
if (curr?.kind === 'Field') { | ||
resolvePath.push(curr.name.value); | ||
const fieldName = curr.name.value; | ||
const responseKey = curr.alias?.value ?? fieldName; | ||
let field; | ||
if ((0, graphql_1.isObjectType)(currType)) { | ||
field = currType.getFields()[fieldName]; | ||
} | ||
else if ((0, graphql_1.isAbstractType)(currType)) { | ||
for (const possibleType of schema.getPossibleTypes(currType)) { | ||
field = possibleType.getFields()[fieldName]; | ||
if (field) { | ||
break; | ||
} | ||
} | ||
} | ||
if ((0, graphql_1.isListType)(field?.type)) { | ||
resolvePath.push('@'); | ||
} | ||
resolvePath.push(responseKey); | ||
if (field?.type) { | ||
currType = (0, graphql_1.getNamedType)(field.type); | ||
} | ||
} | ||
@@ -164,0 +176,0 @@ } |
@@ -1,4 +0,4 @@ | ||
import { getNamedType, isInterfaceType, isIntrospectionType, isObjectType, isUnionType, } from 'graphql'; | ||
import { getNamedType, getOperationAST, isAbstractType, isInterfaceType, isIntrospectionType, isListType, isObjectType, isUnionType, } from 'graphql'; | ||
import { useExtendedValidation } from '@envelop/extended-validation'; | ||
import { createGraphQLError, getDirectiveExtensions, shouldIncludeNode, } from '@graphql-tools/utils'; | ||
import { createGraphQLError, getDefinedRootType, getDirectiveExtensions, shouldIncludeNode, } from '@graphql-tools/utils'; | ||
export const DIRECTIVE_SDL = /* GraphQL */ ` | ||
@@ -118,13 +118,2 @@ directive @authenticated on FIELD_DEFINITION | OBJECT | INTERFACE | ||
function AuthorizationExtendedValidationRule(context, args) { | ||
const operations = {}; | ||
const fragments = {}; | ||
for (const definition of args.document.definitions) { | ||
if (definition.kind === 'OperationDefinition') { | ||
operations[definition.name?.value ?? args.operationName ?? 'Anonymous'] = | ||
definition; | ||
} | ||
else if (definition.kind === 'FragmentDefinition') { | ||
fragments[definition.name.value] = definition; | ||
} | ||
} | ||
const user = args.contextValue[contextFieldName]; | ||
@@ -151,6 +140,29 @@ const handleField = ({ node: fieldNode, path, }, parentType) => { | ||
let curr = args.document; | ||
const operationAST = getOperationAST(args.document, args.operationName); | ||
const operationType = operationAST?.operation ?? 'query'; | ||
let currType = getDefinedRootType(schema, operationType); | ||
for (const pathItem of path) { | ||
curr = curr[pathItem]; | ||
if (curr?.kind === 'Field') { | ||
resolvePath.push(curr.name.value); | ||
const fieldName = curr.name.value; | ||
const responseKey = curr.alias?.value ?? fieldName; | ||
let field; | ||
if (isObjectType(currType)) { | ||
field = currType.getFields()[fieldName]; | ||
} | ||
else if (isAbstractType(currType)) { | ||
for (const possibleType of schema.getPossibleTypes(currType)) { | ||
field = possibleType.getFields()[fieldName]; | ||
if (field) { | ||
break; | ||
} | ||
} | ||
} | ||
if (isListType(field?.type)) { | ||
resolvePath.push('@'); | ||
} | ||
resolvePath.push(responseKey); | ||
if (field?.type) { | ||
currType = getNamedType(field.type); | ||
} | ||
} | ||
@@ -157,0 +169,0 @@ } |
{ | ||
"name": "@envelop/generic-auth", | ||
"version": "8.0.0-alpha-20240812203512-43551114", | ||
"version": "8.0.0", | ||
"sideEffects": false, | ||
"peerDependencies": { | ||
"@envelop/core": "^5.0.0", | ||
"@envelop/core": "^5.0.2", | ||
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" | ||
}, | ||
"dependencies": { | ||
"@envelop/extended-validation": "4.1.0-alpha-20240812203512-43551114", | ||
"@envelop/extended-validation": "^4.1.0", | ||
"@graphql-tools/utils": "^10.5.1", | ||
@@ -12,0 +12,0 @@ "tslib": "^2.5.0" |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
55387
3.55%662
3.76%1
-50%+ Added
- Removed