Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (isField(selection)) {
const fieldResult = handleMissing(
this.executeField(object, typename, selection, execContext),
);
if (typeof fieldResult !== 'undefined') {
objectsToMerge.push({
[resultKeyNameFromField(selection)]: fieldResult,
});
}
} else {
let fragment: InlineFragmentNode | FragmentDefinitionNode;
if (isInlineFragment(selection)) {
fragment = selection;
} else {
// This is a named fragment
fragment = fragmentMap[selection.name.value];
if (!fragment) {
throw new InvariantError(`No fragment named ${selection.name.value}`);
}
}
const typeCondition =
fragment.typeCondition && fragment.typeCondition.name.value;
const match =
!typeCondition ||
execContext.fragmentMatcher(rootValue, typeCondition, contextValue);
if (isField(selection)) {
const fieldResult = executeField(selection, rootValue, execContext);
const resultFieldKey = resultKeyNameFromField(selection);
if (fieldResult !== undefined) {
if (result[resultFieldKey] === undefined) {
result[resultFieldKey] = fieldResult;
} else {
merge(result[resultFieldKey], fieldResult);
}
}
} else {
let fragment: InlineFragmentNode | FragmentDefinitionNode;
if (isInlineFragment(selection)) {
fragment = selection;
} else {
// This is a named fragment
fragment = fragmentMap[selection.name.value];
if (!fragment) {
throw new Error(`No fragment named ${selection.name.value}`);
}
}
const typeCondition = fragment.typeCondition.name.value;
if (execContext.fragmentMatcher(rootValue, typeCondition, contextValue)) {
const fragmentResult = executeSelectionSet(
fragment.selectionSet,
rootValue,
return;
}
if (isField(selection)) {
const fieldResult = handleMissing(executeField(selection, rootValue, execContext));
if (typeof fieldResult !== 'undefined') {
merge(finalResult.result, {
[resultKeyNameFromField(selection)]: fieldResult,
});
}
} else {
let fragment: InlineFragmentNode | FragmentDefinitionNode;
if (isInlineFragment(selection)) {
fragment = selection;
} else {
// This is a named fragment
fragment = fragmentMap[selection.name.value];
if (!fragment) {
throw new Error(`No fragment named ${selection.name.value}`);
}
}
const typeCondition = fragment.typeCondition.name.value;
const match = execContext.fragmentMatcher(rootValue, typeCondition, contextValue);
if (match) {
let fragmentExecResult = executeSelectionSet(
fragment.selectionSet,
if (isField(selection)) {
return this.resolveField(selection, rootValue, execContext).then(
fieldResult => {
if (typeof fieldResult !== 'undefined') {
resultsToMerge.push({
[resultKeyNameFromField(selection)]: fieldResult,
} as TData);
}
},
);
}
let fragment: InlineFragmentNode | FragmentDefinitionNode;
if (isInlineFragment(selection)) {
fragment = selection;
} else {
// This is a named fragment.
fragment = fragmentMap[selection.name.value];
invariant(fragment, `No fragment named ${selection.name.value}`);
}
if (fragment && fragment.typeCondition) {
const typeCondition = fragment.typeCondition.name.value;
if (execContext.fragmentMatcher(rootValue, typeCondition, context)) {
return this.resolveSelectionSet(
fragment.selectionSet,
rootValue,
execContext,
).then(fragmentResult => {
resultsToMerge.push(fragmentResult);
const resultFieldKey = resultKeyNameFromField(selection)
if (fieldResult === undefined) {
return
}
return {
type: 'field',
key: resultFieldKey,
value: fieldResult
}
}
let fragment
if (isInlineFragment(selection)) {
fragment = selection
} else {
// This is a named fragment
fragment = fragmentMap[selection.name.value]
if (!fragment) {
throw new Error(`No fragment named ${selection.name.value}`)
}
}
const typeCondition = fragment.typeCondition.name.value
if (execContext.fragmentMatcher(rootValue, typeCondition, contextValue)) {
const fragmentResult = await executeSelectionSet(
fragment.selectionSet,
rootValue,
// we just print a warning for the time being.
//throw new WriteError(`Missing field ${resultFieldKey} in ${JSON.stringify(result, null, 2).substring(0, 100)}`);
invariant.warn(
`Missing field ${resultFieldKey} in ${JSON.stringify(
result,
null,
2,
).substring(0, 100)}`,
);
}
}
} else {
// This is not a field, so it must be a fragment, either inline or named
let fragment: InlineFragmentNode | FragmentDefinitionNode;
if (isInlineFragment(selection)) {
fragment = selection;
} else {
// Named fragment
fragment = (fragmentMap || {})[selection.name.value];
invariant(fragment, `No fragment named ${selection.name.value}.`);
}
let matches = true;
if (context.fragmentMatcherFunction && fragment.typeCondition) {
// TODO we need to rewrite the fragment matchers for this to work properly and efficiently
// Right now we have to pretend that we're passing in an idValue and that there's a store
// on the context.
const id = dataId || 'self';
const idValue = toIdValue({ id, typename: undefined });
const fakeContext: ReadStoreContext = {
// NOTE: fakeContext always uses ObjectCache
if (isField(selection)) {
const fieldResult = executeField(selection, rootValue, execContext);
const resultFieldKey = resultKeyNameFromField(selection);
if (fieldResult !== undefined) {
if (result[resultFieldKey] === undefined) {
result[resultFieldKey] = fieldResult;
} else {
merge(result[resultFieldKey], fieldResult);
}
}
} else {
let fragment: InlineFragmentNode | FragmentDefinitionNode;
if (isInlineFragment(selection)) {
fragment = selection;
} else {
// This is a named fragment
fragment = fragmentMap[selection.name.value];
if (!fragment) {
throw new Error(`No fragment named ${selection.name.value}`);
}
}
const typeCondition = fragment.typeCondition.name.value;
if (execContext.fragmentMatcher(rootValue, typeCondition, contextValue)) {
const fragmentResult = executeSelectionSet(
fragment.selectionSet,
rootValue,
const resultFieldKey = resultKeyNameFromField(selection);
if (fieldResult !== undefined) {
if (result[resultFieldKey] === undefined) {
result[resultFieldKey] = fieldResult;
} else {
merge(result[resultFieldKey], fieldResult);
}
}
return;
}
let fragment: InlineFragmentNode | FragmentDefinitionNode;
if (isInlineFragment(selection)) {
fragment = selection;
} else {
// This is a named fragment
fragment = fragmentMap[selection.name.value];
if (!fragment) {
throw new Error(`No fragment named ${selection.name.value}`);
}
}
const typeCondition = fragment.typeCondition.name.value;
if (execContext.fragmentMatcher(rootValue, typeCondition, contextValue)) {
const fragmentResult = await executeSelectionSet(
fragment.selectionSet,
rootValue,
}
else {
var isDefered = selection.directives &&
selection.directives.length &&
selection.directives.some(function (directive) { return directive.name && directive.name.value === 'defer'; });
if (!isDefered && context.fragmentMatcherFunction) {
if (!isProduction()) {
console.warn("Missing field " + resultFieldKey + " in " + JSON.stringify(result, null, 2).substring(0, 100));
}
}
}
}
}
else {
var fragment = void 0;
if (isInlineFragment(selection)) {
fragment = selection;
}
else {
fragment = (fragmentMap || {})[selection.name.value];
if (!fragment) {
throw new Error("No fragment named " + selection.name.value + ".");
}
}
var matches = true;
if (context.fragmentMatcherFunction && fragment.typeCondition) {
var idValue = { type: 'id', id: 'self', generated: false };
var fakeContext = {
store: new ObjectCache({ self: result }),
returnPartialData: false,
hasMissingField: false,
cacheResolvers: {},
currentSelectionSet.selections.forEach(node => {
if (isInlineFragment(node)) {
findRestDirectivesThenInsertNullsForOmittedFields(
resultKey,
current,
mainDefinition,
fragmentMap,
node.selectionSet,
);
} else if (node.kind === 'FragmentSpread') {
const fragment = fragmentMap[node.name.value];
findRestDirectivesThenInsertNullsForOmittedFields(
resultKey,
current,
mainDefinition,
fragmentMap,
fragment.selectionSet,
);