Skip to content
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Don't generate fields that represent compositions of aspects within mutation types that represent services
- Moved the `GraphQLAdapter` module to the root directory (`index.js`), simplifying the import process and reducing the required typing.
- Disabled conjunction on the same field for the following operators:
+ `eq` (Equal)
+ `gt` (Greater Than)
+ `ge` (Greater Than or Equal)
+ `le` (Less Than or Equal)
+ `lt` (Less Than)
+ `startswith`
+ `endswith`

### Fixed

Expand Down
15 changes: 14 additions & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,22 @@ const STRING_OPERATIONS = {
contains: 'contains'
}

const OPERATOR_CONJUNCTION_SUPPORT = {
[RELATIONAL_OPERATORS.eq]: false,
[RELATIONAL_OPERATORS.ne]: true,
[RELATIONAL_OPERATORS.gt]: false,
[RELATIONAL_OPERATORS.ge]: false,
[RELATIONAL_OPERATORS.le]: false,
[RELATIONAL_OPERATORS.lt]: false,
[STRING_OPERATIONS.startswith]: false,
[STRING_OPERATIONS.endswith]: false,
[STRING_OPERATIONS.contains]: true
}

module.exports = {
CONNECTION_FIELDS,
ARGS,
RELATIONAL_OPERATORS,
STRING_OPERATIONS
STRING_OPERATIONS,
OPERATOR_CONJUNCTION_SUPPORT
}
13 changes: 10 additions & 3 deletions lib/resolvers/parse/ast/fromObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,20 @@ const _arrayToListValue = array => ({
const _variableToValue = variable => {
if (Array.isArray(variable)) {
return _arrayToListValue(variable)
} else if (isPlainObject(variable)) {
}

if (isPlainObject(variable)) {
return _objectToObjectValue(variable)
} else if (variable === null) {
}

if (variable === null) {
return _nullValue
} else if (variable === undefined) {
}

if (variable === undefined) {
return undefined
}

return _valueToGenericScalarValue(variable)
}

Expand Down
1 change: 0 additions & 1 deletion lib/resolvers/parse/ast2cqn/where.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const _to_xpr = (ref, gqlOperator, value) => {
const val = { val: value }

if (STRING_OPERATIONS[gqlOperator]) return [{ func: cdsOperator, args: [ref, val] }]

return [ref, cdsOperator, val]
}

Expand Down
12 changes: 8 additions & 4 deletions lib/schema/args/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
const { gqlName } = require('../../utils')
const { hasScalarFields, shouldElementBeIgnored } = require('../util')
const { cdsToGraphQLScalarType } = require('../types/scalar')
const { RELATIONAL_OPERATORS, STRING_OPERATIONS } = require('../../constants')
const { RELATIONAL_OPERATORS, STRING_OPERATIONS, OPERATOR_CONJUNCTION_SUPPORT } = require('../../constants')
const {
GraphQLBinary,
GraphQLDate,
Expand Down Expand Up @@ -83,10 +83,14 @@ module.exports = cache => {
const _generateFilterType = (gqlType, operations) => {
const filterName = gqlType.name + '_filter'

const cacheFilterType = cache.get(filterName)
if (cacheFilterType) return cacheFilterType
const cachedFilterType = cache.get(filterName)
if (cachedFilterType) return cachedFilterType

const fields = Object.fromEntries(operations.map(op => [[op], { type: new GraphQLList(gqlType) }]))
const ops = operations.map(op => [
[op],
{ type: OPERATOR_CONJUNCTION_SUPPORT[op] ? new GraphQLList(gqlType) : gqlType }
])
const fields = Object.fromEntries(ops)
const newFilterType = new GraphQLInputObjectType({ name: filterName, fields })
cache.set(filterName, newFilterType)

Expand Down
66 changes: 33 additions & 33 deletions test/schemas/bookshop-graphql.gql
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ The `Binary` scalar type represents binary values as `base64url` encoded strings
scalar Binary

input Binary_filter {
eq: [Binary]
eq: Binary
ne: [Binary]
}

Expand Down Expand Up @@ -1277,11 +1277,11 @@ The `Date` scalar type represents date values as strings in the ISO 8601 format
scalar Date

input Date_filter {
eq: [Date]
ge: [Date]
gt: [Date]
le: [Date]
lt: [Date]
eq: Date
ge: Date
gt: Date
le: Date
lt: Date
ne: [Date]
}

Expand All @@ -1291,11 +1291,11 @@ The `Decimal` scalar type represents exact signed decimal values. Decimal repres
scalar Decimal

input Decimal_filter {
eq: [Decimal]
ge: [Decimal]
gt: [Decimal]
le: [Decimal]
lt: [Decimal]
eq: Decimal
ge: Decimal
gt: Decimal
le: Decimal
lt: Decimal
ne: [Decimal]
}

Expand All @@ -1305,20 +1305,20 @@ The `Int16` scalar type represents 16-bit non-fractional signed whole numeric va
scalar Int16

input Int16_filter {
eq: [Int16]
ge: [Int16]
gt: [Int16]
le: [Int16]
lt: [Int16]
eq: Int16
ge: Int16
gt: Int16
le: Int16
lt: Int16
ne: [Int16]
}

input Int_filter {
eq: [Int]
ge: [Int]
gt: [Int]
le: [Int]
lt: [Int]
eq: Int
ge: Int
gt: Int
le: Int
lt: Int
ne: [Int]
}

Expand All @@ -1339,14 +1339,14 @@ enum SortDirection {

input String_filter {
contains: [String]
endswith: [String]
eq: [String]
ge: [String]
gt: [String]
le: [String]
lt: [String]
endswith: String
eq: String
ge: String
gt: String
le: String
lt: String
ne: [String]
startswith: [String]
startswith: String
}

"""
Expand All @@ -1355,10 +1355,10 @@ The `Timestamp` scalar type represents timestamp values as strings in the ISO 86
scalar Timestamp

input Timestamp_filter {
eq: [Timestamp]
ge: [Timestamp]
gt: [Timestamp]
le: [Timestamp]
lt: [Timestamp]
eq: Timestamp
ge: Timestamp
gt: Timestamp
le: Timestamp
lt: Timestamp
ne: [Timestamp]
}
24 changes: 12 additions & 12 deletions test/schemas/edge-cases/field-named-localized.gql
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ input FieldNamedLocalizedService_localized_orderBy {
}

input Int_filter {
eq: [Int]
ge: [Int]
gt: [Int]
le: [Int]
lt: [Int]
eq: Int
ge: Int
gt: Int
le: Int
lt: Int
ne: [Int]
}

Expand All @@ -137,12 +137,12 @@ enum SortDirection {

input String_filter {
contains: [String]
endswith: [String]
eq: [String]
ge: [String]
gt: [String]
le: [String]
lt: [String]
endswith: String
eq: String
ge: String
gt: String
le: String
lt: String
ne: [String]
startswith: [String]
startswith: String
}
10 changes: 5 additions & 5 deletions test/schemas/model-structure/composition-of-aspect.gql
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ type CompositionOfAspectService_input {
}

input ID_filter {
eq: [ID]
ge: [ID]
gt: [ID]
le: [ID]
lt: [ID]
eq: ID
ge: ID
gt: ID
le: ID
lt: ID
ne: [ID]
}

Expand Down
Loading