Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function executeField(
field: FieldNode,
rootValue: any,
execContext: ExecContext,
): ExecResult {
const { variableValues: variables, contextValue } = execContext;
const fieldName = field.name.value;
const args = argumentsObjectFromField(field, variables);
const info: ExecInfo = {
resultKey: resultKeyNameFromField(field),
directives: getDirectiveInfoFromField(field, variables),
};
const readStoreResult = readStoreResolver(
fieldName,
rootValue,
args,
contextValue,
info,
);
// Handle all scalar types here
if (!field.selectionSet) {
return readStoreResult;
}
// From here down, the field has a selection set, which means it's trying to
function executeField(
field: FieldNode,
rootValue: any,
execContext: ExecContext,
): any {
const { variableValues: variables, contextValue, resolver } = execContext;
const fieldName = field.name.value;
const args = argumentsObjectFromField(field, variables);
const info: ExecInfo = {
isLeaf: !field.selectionSet,
resultKey: resultKeyNameFromField(field),
directives: getDirectiveInfoFromField(field, variables),
};
const result = resolver(fieldName, rootValue, args, contextValue, info);
// Handle all scalar types here
if (!field.selectionSet) {
return result;
}
// From here down, the field has a selection set, which means it's trying to
// query a GraphQLObjectType
if (result == null) {
// Basically any field in a GraphQL response can be null, or missing
return result;
}
const queryWithTypename = addTypenameToDocument(query);
const mainDefinition = getMainDefinition(query);
const context: ResolverContext = {
database: this.database,
findType: fieldDirectives =>
(fieldDirectives.rtdbSub && fieldDirectives.rtdbSub.type) ||
(fieldDirectives.rtdbQuery && fieldDirectives.rtdbQuery.type),
exportVal: {}
};
// Subscription operations must have exactly one root field.
const onlyRootField: FieldNode = mainDefinition.selectionSet.selections[0] as FieldNode;
// get directives
const directives = getDirectiveInfoFromField(onlyRootField, operation.variables);
const rtdbDirectives: SubDirectiveArgs = directives.rtdbSub as any;
return new Observable(observer => {
// we fetch the query outside the graphql-anywhere resolver
// because subscription need to listen to event change
const subQuery = createQuery({
database: this.database,
directives: rtdbDirectives
});
const {event} = rtdbDirectives;
const callback = (snapshot: firebaseDatabase.DataSnapshot) => {
const root: ResolverRoot = {rootSnapshot: snapshot};
graphql(
queryResolver,
queryWithTypename,
root,
async function executeField(
field: FieldNode,
rootValue: any,
execContext: ExecContext,
): Promise {
const { variableValues: variables, contextValue, resolver } = execContext;
const fieldName = field.name.value;
const args = argumentsObjectFromField(field, variables);
const info: ExecInfo = {
isLeaf: !field.selectionSet,
resultKey: resultKeyNameFromField(field),
directives: getDirectiveInfoFromField(field, variables),
field,
};
const result = await resolver(fieldName, rootValue, args, contextValue, info);
// Handle all scalar types here
if (!field.selectionSet) {
return result;
}
// From here down, the field has a selection set, which means it's trying to
// query a GraphQLObjectType
if (result == null) {
// Basically any field in a GraphQL response can be null, or missing
return result;
}
function executeField(
field: FieldNode,
rootValue: any,
execContext: ExecContext,
): any {
const { variableValues: variables, contextValue, resolver } = execContext;
const fieldName = field.name.value;
const args = argumentsObjectFromField(field, variables);
const info: ExecInfo = {
isLeaf: !field.selectionSet,
resultKey: resultKeyNameFromField(field),
directives: getDirectiveInfoFromField(field, variables),
};
const result = resolver(fieldName, rootValue, args, contextValue, info);
// Handle all scalar types here
if (!field.selectionSet) {
return result;
}
// From here down, the field has a selection set, which means it's trying to
// query a GraphQLObjectType
if (result == null) {
// Basically any field in a GraphQL response can be null, or missing
return result;
}
private executeField(
object: StoreObject,
typename: string | void,
field: FieldNode,
execContext: ExecContext,
): ExecResult {
const { variableValues: variables, contextValue } = execContext;
const fieldName = field.name.value;
const args = argumentsObjectFromField(field, variables);
const info: ExecInfo = {
resultKey: resultKeyNameFromField(field),
directives: getDirectiveInfoFromField(field, variables),
};
const readStoreResult = readStoreResolver(
object,
typename,
fieldName,
args,
contextValue,
info,
);
if (Array.isArray(readStoreResult.result)) {
return this.combineExecResults(
readStoreResult,
this.executeSubSelectedArray({
field,
export const fieldHasDirective = (node: FieldNode, directive: string) =>
Object.keys(getDirectiveInfoFromField(node, {}) || {}).some((dir) => dir === directive);
export const getTrackerId = (field: FieldNode, args?: object) => {
const directives = getDirectiveInfoFromField(field, args || {});
if (!(directives.ethpollo && directives.ethpollo.id)) {
throw new Error('Tracker directive not found');
}
return directives.ethpollo.id;
};