Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private delegateToSchema(
operation: Operation,
fieldName: string,
args?: { [key: string]: any },
infoOrQuery?: GraphQLResolveInfo | string,
options?: Options,
): { info: any; result: Promise } {
const info = buildInfo(fieldName, operation, this.schema, infoOrQuery)
const transforms = options && options.transforms ? options.transforms : []
const result = delegateToSchema({
schema: this.schema,
operation,
fieldName,
args: args || {},
context: options && options.context ? options.context : {},
info,
transforms: [
...transforms,
new ReplaceFieldWithFragment(this.schema, this.fragmentReplacements),
],
})
return { info, result }
}
}
return (
args?: { [key: string]: any },
info?: GraphQLResolveInfo | string,
): Promise => {
this.before()
const operation = this.operation
info = buildInfo(rootFieldName, operation, this.schema, info)
return delegateToSchema(
this.schema,
this.fragmentReplacements,
operation,
rootFieldName,
args || {},
{},
info,
)
}
}
delegate(
operation: "query" | "mutation",
fieldName: string,
args: { [key: string]: any },
context: any,
info: GraphQLResolveInfo
) {
return delegateToSchema(
this.schema,
{},
operation,
fieldName,
args,
context,
info
);
}
return async (
args?: { [key: string]: any },
infoOrQuery?: GraphQLResolveInfo | string,
context?: { [key: string]: any },
): Promise> => {
this.before()
const info = buildInfo(
rootFieldName,
'subscription',
this.schema,
infoOrQuery,
)
const iterator = await delegateToSchema(
this.schema,
this.fragmentReplacements,
'subscription',
rootFieldName,
args || {},
context || {},
info,
)
return {
async next() {
const { value } = await iterator.next()
const data = { [info.fieldName]: value.data[rootFieldName] }
return { value: data, done: false }
},
return() {
return (
args?: { [key: string]: any },
info?: GraphQLResolveInfo | string,
context?: { [key: string]: any },
): Promise => {
this.before()
const operation = this.operation
info = buildInfo(rootFieldName, operation, this.schema, info)
return delegateToSchema(
this.schema,
this.fragmentReplacements,
operation,
rootFieldName,
args || {},
context || {},
info,
)
}
}
info = {
...info,
fieldNodes: [{
kind: "Field",
name: {
kind: "Name",
value: mergeQuery,
},
selectionSet: {
kind: "SelectionSet",
selections: info.fieldNodes,
},
} as FieldNode],
};
}
const request = delegateToSchema({
schema,
operation: "query",
fieldName: mergeQuery || info.fieldName,
args: mergeQuery ? { id: parent.id } : args,
context,
info,
});
if (mergeQuery) {
return request.then((requestResult) => requestResult ? requestResult[responseKey] : null);
} else {
return request;
}
}
};
}
graphcool: (parent, args, context, info) => {
return delegateToSchema(
schema,
{},
'query',
'repositoryOwner',
{login: 'graphcool'},
context,
info
)
}
}
delegate(operation: 'query' | 'mutation', prop: string, args, info?: GraphQLResolveInfo | string): Promise {
if (!info) {
info = buildTypeLevelInfo(prop, this.remoteSchema, operation)
} else if (typeof info === 'string') {
info = buildFragmentInfo(prop, this.remoteSchema, operation, info)
}
return delegateToSchema(
this.remoteSchema,
this.fragmentReplacements,
operation,
prop,
args || {},
{},
info,
)
}