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

Relationship API bug fixes & updates #481

Merged
merged 15 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/augment/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ export const buildFieldSelection = ({
args = [],
directives = [],
name = {},
selectionSet = {}
selectionSet = {
kind: Kind.SELECTION_SET,
selections: []
}
}) => {
return {
kind: Kind.FIELD,
Expand Down
1 change: 0 additions & 1 deletion src/augment/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ export const propertyFieldExists = ({
}) => {
const fields = definition.fields || [];
return fields.find(field => {
const fieldName = field.name.value;
const fieldType = field.type;
const unwrappedType = unwrapNamedType({ type: fieldType });
const outputType = unwrappedType.name;
Expand Down
64 changes: 60 additions & 4 deletions src/augment/input-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
buildInputValue,
buildInputObjectType,
buildEnumType,
buildEnumValue
buildEnumValue,
buildFieldSelection
} from './ast';
import {
isNeo4jTemporalType,
Expand Down Expand Up @@ -97,6 +98,7 @@ export const buildQueryFieldArguments = ({
argumentMap = {},
fieldArguments,
fieldDirectives,
typeName,
outputType,
outputTypeWrappers,
isUnionType,
Expand Down Expand Up @@ -167,6 +169,9 @@ export const buildQueryFieldArguments = ({
const argumentIndex = fieldArguments.findIndex(
arg => arg.name.value === FilteringArgument.FILTER
);
if (typeName) {
outputType = `${typeName}${outputType}`;
}
// Does overwrite
if (argumentIndex === -1) {
fieldArguments.push(
Expand Down Expand Up @@ -439,9 +444,7 @@ export const buildFilters = ({ fieldName, fieldConfig, filterTypes = [] }) => {
[TypeWrappers.LIST_TYPE]: true
};
} else if (isPointDistanceFilter) {
fieldConfig.type.name = `${Neo4jTypeName}${
SpatialType.POINT
}DistanceFilter`;
fieldConfig.type.name = `${Neo4jTypeName}${SpatialType.POINT}DistanceFilter`;
}
inputValues.push(
buildInputValue({
Expand All @@ -462,3 +465,56 @@ export const buildFilters = ({ fieldName, fieldConfig, filterTypes = [] }) => {
]
);
};

export const selectUnselectedOrderedFields = ({
selectionFilters,
fieldSelectionSet
}) => {
let orderingArguments = selectionFilters['orderBy'];
const orderedFieldSelectionSet = [];
// cooerce to array if not provided as list
if (orderingArguments) {
// if a single ordering enum argument value is provided,
// cooerce back into an array
if (typeof orderingArguments === 'string') {
orderingArguments = [orderingArguments];
}
orderedFieldSelectionSet.push(...fieldSelectionSet);
// add field selection AST for ordered fields if those fields are
// not selected, since apoc.coll.sortMulti requires data to sort
const orderedFieldNameMap = orderingArguments.reduce(
(uniqueFieldMap, orderingArg) => {
const fieldName = orderingArg.substring(
0,
orderingArg.lastIndexOf('_')
);
// prevent redundant selections
// ex: [datetime_asc, datetime_desc], if provided, would result
// in adding two selections for the datetime field
if (!uniqueFieldMap[fieldName]) uniqueFieldMap[fieldName] = true;
return uniqueFieldMap;
},
{}
);
const orderingArgumentFieldNames = Object.keys(orderedFieldNameMap);
orderingArgumentFieldNames.forEach(orderedFieldName => {
if (
!fieldSelectionSet.some(
field => field.name && field.name.value === orderedFieldName
)
) {
// add the field so that its data can be used for ordering
// since as it is not actually selected, it will be removed
// by default GraphQL post-processing field resolvers
orderedFieldSelectionSet.push(
buildFieldSelection({
name: buildName({
name: orderedFieldName
})
})
);
}
});
}
return orderedFieldSelectionSet;
};
5 changes: 3 additions & 2 deletions src/augment/types/node/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,13 @@ export const augmentNodeTypeFields = ({
config
}) => {
let isIgnoredType = true;
let filterTypeName = `_${typeName}Filter`;
const fields = definition.fields;
if (!isUnionType && !isUnionExtension) {
const fields = definition.fields;
if (!isQueryType) {
if (!nodeInputTypeMap[FilteringArgument.FILTER]) {
nodeInputTypeMap[FilteringArgument.FILTER] = {
name: `_${typeName}Filter`,
name: filterTypeName,
fields: []
};
}
Expand Down
Loading