Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apollo/query-planner

Package Overview
Dependencies
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollo/query-planner - npm Package Compare versions

Comparing version 0.8.2 to 0.9.0

41

dist/buildQueryPlan.js

@@ -58,3 +58,4 @@ "use strict";

debug.groupedValues(groups, debugPrintGroup);
const nodes = groups.map(group => executionNodeForGroup(context, group, rootType));
let counterByReference = { counter: 0 };
const nodes = groups.map(group => executionNodeForGroup(context, group, counterByReference, rootType));
return {

@@ -158,3 +159,12 @@ kind: 'QueryPlan',

}
function executionNodeForGroup(context, { serviceName, fields, requiredFields, internalFragments, mergeAt, dependentGroups, }, parentType) {
function toValidGraphQLName(subgraphName) {
const sanitized = subgraphName
.replace(/-/ig, '_')
.replace(/[^_0-9A-Za-z]/ig, '');
return sanitized.match(/^[0-9].*/i) ? '_' + sanitized : sanitized;
}
function executionNodeForGroup(context, { serviceName, fields, requiredFields, internalFragments, mergeAt, dependentGroups, }, counterByReference, parentType) {
const operationName = context.operation.name
? `${context.operation.name.value}__${toValidGraphQLName(serviceName)}__${counterByReference.counter++}`
: undefined;
const selectionSet = (0, FieldSet_1.selectionSetFromFieldSet)(fields, parentType);

@@ -170,2 +180,3 @@ const requires = requiredFields.length > 0

internalFragments,
operationName,
})

@@ -177,2 +188,3 @@ : operationForRootFetch({

operation: context.operation.operation,
operationName,
});

@@ -187,2 +199,5 @@ const inclusionConditions = collectInclusionConditions(operation);

...(inclusionConditions ? { inclusionConditions } : {}),
operationName,
operationKind: operation.definitions[0]
.operation,
};

@@ -197,3 +212,3 @@ const node = mergeAt && mergeAt.length > 0

if (dependentGroups.length > 0) {
const dependentNodes = dependentGroups.map(dependentGroup => executionNodeForGroup(context, dependentGroup));
const dependentNodes = dependentGroups.map((dependentGroup) => executionNodeForGroup(context, dependentGroup, counterByReference));
return flatWrap('Sequence', [node, flatWrap('Parallel', dependentNodes)]);

@@ -208,3 +223,3 @@ }

}
function operationForRootFetch({ selectionSet, variableUsages, internalFragments, operation = 'query', }) {
function operationForRootFetch({ selectionSet, variableUsages, internalFragments, operation = 'query', operationName, }) {
return {

@@ -218,2 +233,10 @@ kind: graphql_1.Kind.DOCUMENT,

variableDefinitions: mapFetchNodeToVariableDefinitions(variableUsages),
...(operationName
? {
name: {
kind: graphql_1.Kind.NAME,
value: operationName,
},
}
: {}),
},

@@ -224,3 +247,3 @@ ...internalFragments,

}
function operationForEntitiesFetch({ selectionSet, variableUsages, internalFragments, }) {
function operationForEntitiesFetch({ selectionSet, variableUsages, internalFragments, operationName }) {
const representationsVariable = {

@@ -275,2 +298,10 @@ kind: graphql_1.Kind.VARIABLE,

},
...(operationName
? {
name: {
kind: graphql_1.Kind.NAME,
value: operationName,
},
}
: {}),
},

@@ -277,0 +308,0 @@ ...internalFragments,

4

dist/QueryPlan.d.ts

@@ -1,2 +0,2 @@

import { SelectionNode as GraphQLJSSelectionNode } from 'graphql';
import { OperationTypeNode, SelectionNode as GraphQLJSSelectionNode } from 'graphql';
export declare type ResponsePath = (string | number)[];

@@ -26,2 +26,4 @@ export interface QueryPlan {

}[];
operationName?: string;
operationKind: OperationTypeNode;
}

@@ -28,0 +30,0 @@ export interface FlattenNode {

{
"name": "@apollo/query-planner",
"version": "0.8.2",
"version": "0.9.0",
"description": "Apollo Query Planner",

@@ -35,3 +35,3 @@ "author": "Apollo <packages@apollographql.com>",

},
"gitHead": "5a5f30f059c0a1f96ebffd2b5c766b90f8899c04"
"gitHead": "6103260972dc4913aa640c49d5630d2f0a77cec3"
}

@@ -136,4 +136,6 @@ import { isNotNullOrUndefined } from './utilities/predicates';

let counterByReference = { counter: 0 };
const nodes = groups.map(group =>
executionNodeForGroup(context, group, rootType),
executionNodeForGroup(context, group, counterByReference, rootType),
);

@@ -314,2 +316,18 @@

function toValidGraphQLName(subgraphName: string): string {
// We have almost no limitations on subgraph names, so we cannot use them inside query names
// without some cleaning up. GraphQL names can only be: [_A-Za-z][_0-9A-Za-z]*.
// To do so, we:
// 1. replace '-' by '_' because the former is not allowed but it's probably pretty
// common and using the later should be fairly readable.
// 2. remove any character in what remains that is not allowed.
// 3. Unsure the first character is not a number, and if it is, add a leading `_`.
// Note that this could theoretically lead to substantial changes to the name but should
// work well in practice (and if it's a huge problem for someone, we can change it).
const sanitized = subgraphName
.replace(/-/ig, '_')
.replace(/[^_0-9A-Za-z]/ig, '');
return sanitized.match(/^[0-9].*/i) ? '_' + sanitized : sanitized;
}
function executionNodeForGroup(

@@ -325,4 +343,10 @@ context: QueryPlanningContext,

}: FetchGroup,
counterByReference: { counter: number },
parentType?: GraphQLCompositeType,
): PlanNode {
const operationName = context.operation.name
? `${context.operation.name.value}__${toValidGraphQLName(
serviceName,
)}__${counterByReference.counter++}`
: undefined;
const selectionSet = selectionSetFromFieldSet(fields, parentType);

@@ -343,2 +367,3 @@ const requires =

internalFragments,
operationName,
})

@@ -350,2 +375,3 @@ : operationForRootFetch({

operation: context.operation.operation,
operationName,
});

@@ -362,2 +388,5 @@

...(inclusionConditions ? { inclusionConditions } : {}),
operationName,
operationKind: (operation.definitions[0] as OperationDefinitionNode)
.operation,
};

@@ -375,4 +404,4 @@

if (dependentGroups.length > 0) {
const dependentNodes = dependentGroups.map(dependentGroup =>
executionNodeForGroup(context, dependentGroup),
const dependentNodes = dependentGroups.map((dependentGroup) =>
executionNodeForGroup(context, dependentGroup, counterByReference),
);

@@ -401,2 +430,3 @@

operation = 'query' as any,
operationName,
}: {

@@ -407,2 +437,3 @@ selectionSet: SelectionSetNode;

operation?: OperationTypeNode;
operationName?: string;
}): DocumentNode {

@@ -417,2 +448,10 @@ return {

variableDefinitions: mapFetchNodeToVariableDefinitions(variableUsages),
...(operationName
? {
name: {
kind: Kind.NAME,
value: operationName,
},
}
: {}),
},

@@ -428,2 +467,3 @@ ...internalFragments,

internalFragments,
operationName
}: {

@@ -433,2 +473,3 @@ selectionSet: SelectionSetNode;

internalFragments: Set<FragmentDefinitionNode>;
operationName?: string;
}): DocumentNode {

@@ -446,15 +487,17 @@ const representationsVariable: VariableNode = {

operation: 'query' as any,
variableDefinitions: ([
{
kind: Kind.VARIABLE_DEFINITION,
variable: representationsVariable,
type: {
kind: Kind.NON_NULL_TYPE,
variableDefinitions: (
[
{
kind: Kind.VARIABLE_DEFINITION,
variable: representationsVariable,
type: {
kind: Kind.LIST_TYPE,
kind: Kind.NON_NULL_TYPE,
type: {
kind: Kind.NON_NULL_TYPE,
kind: Kind.LIST_TYPE,
type: {
kind: Kind.NAMED_TYPE,
name: { kind: Kind.NAME, value: '_Any' },
kind: Kind.NON_NULL_TYPE,
type: {
kind: Kind.NAMED_TYPE,
name: { kind: Kind.NAME, value: '_Any' },
},
},

@@ -464,6 +507,4 @@ },

},
},
] as VariableDefinitionNode[]).concat(
mapFetchNodeToVariableDefinitions(variableUsages),
),
] as VariableDefinitionNode[]
).concat(mapFetchNodeToVariableDefinitions(variableUsages)),
selectionSet: {

@@ -489,2 +530,10 @@ kind: Kind.SELECTION_SET,

},
...(operationName
? {
name: {
kind: Kind.NAME,
value: operationName,
},
}
: {}),
},

@@ -491,0 +540,0 @@ ...internalFragments,

@@ -1,2 +0,2 @@

import { Kind, SelectionNode as GraphQLJSSelectionNode } from 'graphql';
import { Kind, OperationTypeNode, SelectionNode as GraphQLJSSelectionNode } from 'graphql';
import prettyFormat from 'pretty-format';

@@ -34,2 +34,4 @@ import { queryPlanSerializer, astSerializer } from './snapshotSerializers';

}[]
operationName?: string;
operationKind: OperationTypeNode;
}

@@ -36,0 +38,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc