MCPcopy Index your code
hub / github.com/StarpTech/FastGraph / requiresAuth

Function requiresAuth

src/graphql-utils.ts:93–131  ·  view source on GitHub ↗
(
  directiveName: string,
  schema: GraphQLSchema,
  ast: DocumentNode,
)

Source from the content-addressed store, hash-verified

91}
92
93export function requiresAuth(
94 directiveName: string,
95 schema: GraphQLSchema,
96 ast: DocumentNode,
97): boolean {
98 const typeInfo = new TypeInfo(schema)
99 let result = false
100
101 visit(
102 ast,
103 visitWithTypeInfo(typeInfo, {
104 enter(node) {
105 if (node.kind === 'FragmentSpread' || node.kind === 'InlineFragment') {
106 const type = typeInfo.getParentType()
107 if (type) {
108 if (
109 type.astNode?.kind === 'InterfaceTypeDefinition' ||
110 type.astNode?.kind === 'ObjectTypeDefinition'
111 ) {
112 result = !!type.astNode?.fields?.some((field) =>
113 hasAuthDirective(field, directiveName),
114 )
115 } else {
116 result = hasAuthDirective(type.astNode, directiveName)
117 }
118 }
119 } else if (node.kind === 'Field') {
120 const field = typeInfo.getFieldDef()
121 if (field) {
122 result = hasAuthDirective(field.astNode, directiveName)
123 }
124 }
125 if (result) return BREAK
126 },
127 }),
128 )
129
130 return result
131}
132
133export const buildGraphQLSchema = (schema: string) => {
134 return buildSchema(schema, {

Callers 2

graphqlFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected