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

Field arguments and filters for list type fields #513

Merged
merged 17 commits into from
Sep 25, 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
1 change: 1 addition & 0 deletions src/augment/augment.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { augmentDirectiveDefinitions } from './directives';
import { extractResolversFromSchema, augmentResolvers } from './resolvers';
import { addAuthDirectiveImplementations } from '../auth';

/**
* The main export for augmenting an SDL document
*/
Expand Down
27 changes: 27 additions & 0 deletions src/augment/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,30 @@ export const getDirectiveArgument = ({ directive, name }) => {
}
return value;
};

export const augmentDirectives = ({ directives = [] }) => {
let cypherDirective = getDirective({
directives,
name: DirectiveDefinition.CYPHER
});
if (cypherDirective) {
cypherDirective = escapeCypherStatement({
directive: cypherDirective
});
}
return directives;
};

const escapeCypherStatement = ({ directive }) => {
const arg = directive.arguments.find(arg => arg.name.value === 'statement');
if (arg) {
const value = arg.value;
if (value && value.kind === Kind.STRING && value.block) {
// Negative lookbehind assertion regex
const unescapedDoubleQuotes = /(?<!\\)"/g;
const escaped = value.value.replace(unescapedDoubleQuotes, '\\"');
arg.value.value = escaped;
}
}
return directive;
};
22 changes: 6 additions & 16 deletions src/augment/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,16 @@ export const TypeWrappers = {
NON_NULL_LIST_TYPE: 'isNonNullListType'
};

/**
* Predicate function identifying whether a GraphQL NamedType
* contained in a type was wrapped with a NonNullType wrapper
*/
export const isNonNullNamedTypeField = ({ wrappers = {} }) =>
wrappers[TypeWrappers.NON_NULL_NAMED_TYPE];

/**
* Predicate function identifying whether a type was wrapped
* with a GraphQL ListType wrapper
*/
export const isListTypeField = ({ wrappers = {} }) =>
wrappers[TypeWrappers.LIST_TYPE];

/**
* Predicate function identifying whether a GraphQL ListType
* contained in a type was wrapped with a NonNullType wrapper
*/
export const isNonNullListTypeField = ({ wrappers = {} }) =>
wrappers[TypeWrappers.NON_NULL_LIST_TYPE];
export const isListTypeField = ({ field = {} }) => {
const type = field.type;
const unwrappedType = unwrapNamedType({ type });
const typeWrappers = unwrappedType.wrappers;
return typeWrappers[TypeWrappers.LIST_TYPE];
};

/**
* A helper function that reduces the type wrappers of a given type
Expand Down
Loading