Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Commit 4984768

Browse files
authoredJul 24, 2020
Relationship API bug fixes & updates (#481)
* adds default selection set to buildFieldSelection used when adding selections for unselected ordered fields * removes unused variable * adds selectUnselectedOrderedFields for selection independet ordering updates buildQueryFieldArguments to support appropriate type names for filtering vs ordering argument types * Update node.js * updates for pagination and ordering on relationship types adds getTypeDefiningField to support appropriate translation of relationship type fields when querying incoming nodes of the .from field in a sub-selection of the .to field, or visa versa * updates for pagination and ordering on relationship types * removes comments * uses selectUnselectedOrderedFields to support selection independent ordering also updates function arguments for the @relation field and type translation functions for use in support for ordering * translates ordering arguments and interfaces for relationship types updates decideRelationFilterMetadata to better determine the direction of the relationship path pattern used when filtering relationship type fields * Update cypherTestHelpers.js * Update filterTck.md * Update parser.js * Update testSchema.js * Update augmentSchemaTest.test.js * Update cypherTest.test.js
1 parent 270f02f commit 4984768

15 files changed

+3223
-380
lines changed
 

‎src/augment/ast.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,10 @@ export const buildFieldSelection = ({
209209
args = [],
210210
directives = [],
211211
name = {},
212-
selectionSet = {}
212+
selectionSet = {
213+
kind: Kind.SELECTION_SET,
214+
selections: []
215+
}
213216
}) => {
214217
return {
215218
kind: Kind.FIELD,

‎src/augment/fields.js

-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ export const propertyFieldExists = ({
251251
}) => {
252252
const fields = definition.fields || [];
253253
return fields.find(field => {
254-
const fieldName = field.name.value;
255254
const fieldType = field.type;
256255
const unwrappedType = unwrapNamedType({ type: fieldType });
257256
const outputType = unwrappedType.name;

‎src/augment/input-values.js

+60-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
buildInputValue,
66
buildInputObjectType,
77
buildEnumType,
8-
buildEnumValue
8+
buildEnumValue,
9+
buildFieldSelection
910
} from './ast';
1011
import {
1112
isNeo4jTemporalType,
@@ -97,6 +98,7 @@ export const buildQueryFieldArguments = ({
9798
argumentMap = {},
9899
fieldArguments,
99100
fieldDirectives,
101+
typeName,
100102
outputType,
101103
outputTypeWrappers,
102104
isUnionType,
@@ -167,6 +169,9 @@ export const buildQueryFieldArguments = ({
167169
const argumentIndex = fieldArguments.findIndex(
168170
arg => arg.name.value === FilteringArgument.FILTER
169171
);
172+
if (typeName) {
173+
outputType = `${typeName}${outputType}`;
174+
}
170175
// Does overwrite
171176
if (argumentIndex === -1) {
172177
fieldArguments.push(
@@ -439,9 +444,7 @@ export const buildFilters = ({ fieldName, fieldConfig, filterTypes = [] }) => {
439444
[TypeWrappers.LIST_TYPE]: true
440445
};
441446
} else if (isPointDistanceFilter) {
442-
fieldConfig.type.name = `${Neo4jTypeName}${
443-
SpatialType.POINT
444-
}DistanceFilter`;
447+
fieldConfig.type.name = `${Neo4jTypeName}${SpatialType.POINT}DistanceFilter`;
445448
}
446449
inputValues.push(
447450
buildInputValue({
@@ -462,3 +465,56 @@ export const buildFilters = ({ fieldName, fieldConfig, filterTypes = [] }) => {
462465
]
463466
);
464467
};
468+
469+
export const selectUnselectedOrderedFields = ({
470+
selectionFilters,
471+
fieldSelectionSet
472+
}) => {
473+
let orderingArguments = selectionFilters['orderBy'];
474+
const orderedFieldSelectionSet = [];
475+
// cooerce to array if not provided as list
476+
if (orderingArguments) {
477+
// if a single ordering enum argument value is provided,
478+
// cooerce back into an array
479+
if (typeof orderingArguments === 'string') {
480+
orderingArguments = [orderingArguments];
481+
}
482+
orderedFieldSelectionSet.push(...fieldSelectionSet);
483+
// add field selection AST for ordered fields if those fields are
484+
// not selected, since apoc.coll.sortMulti requires data to sort
485+
const orderedFieldNameMap = orderingArguments.reduce(
486+
(uniqueFieldMap, orderingArg) => {
487+
const fieldName = orderingArg.substring(
488+
0,
489+
orderingArg.lastIndexOf('_')
490+
);
491+
// prevent redundant selections
492+
// ex: [datetime_asc, datetime_desc], if provided, would result
493+
// in adding two selections for the datetime field
494+
if (!uniqueFieldMap[fieldName]) uniqueFieldMap[fieldName] = true;
495+
return uniqueFieldMap;
496+
},
497+
{}
498+
);
499+
const orderingArgumentFieldNames = Object.keys(orderedFieldNameMap);
500+
orderingArgumentFieldNames.forEach(orderedFieldName => {
501+
if (
502+
!fieldSelectionSet.some(
503+
field => field.name && field.name.value === orderedFieldName
504+
)
505+
) {
506+
// add the field so that its data can be used for ordering
507+
// since as it is not actually selected, it will be removed
508+
// by default GraphQL post-processing field resolvers
509+
orderedFieldSelectionSet.push(
510+
buildFieldSelection({
511+
name: buildName({
512+
name: orderedFieldName
513+
})
514+
})
515+
);
516+
}
517+
});
518+
}
519+
return orderedFieldSelectionSet;
520+
};

‎src/augment/types/node/node.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,13 @@ export const augmentNodeTypeFields = ({
197197
config
198198
}) => {
199199
let isIgnoredType = true;
200+
let filterTypeName = `_${typeName}Filter`;
201+
const fields = definition.fields;
200202
if (!isUnionType && !isUnionExtension) {
201-
const fields = definition.fields;
202203
if (!isQueryType) {
203204
if (!nodeInputTypeMap[FilteringArgument.FILTER]) {
204205
nodeInputTypeMap[FilteringArgument.FILTER] = {
205-
name: `_${typeName}Filter`,
206+
name: filterTypeName,
206207
fields: []
207208
};
208209
}

0 commit comments

Comments
 (0)