Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of logical operations #13

Open
FluorescentHallucinogen opened this issue Jan 29, 2019 · 6 comments
Open

Add support of logical operations #13

FluorescentHallucinogen opened this issue Jan 29, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@FluorescentHallucinogen

In current implementation rules inside @constraint directive are combined by logical (boolean) AND:

input BookInput {
  title: String! @constraint(minLength: 5, format: "email")
}

Custom directives in GraphQL are also combined by AND:

input BookInput {
  title: String! @constraint(minLength: 5) @constraint(format: "email")
}

What about adding support of logic operations (AND, OR and NOT) for nest rules (similar to https://github.com/maticzav/graphql-shield#and-or-not)? Something like (the syntax is subject to discussion):

@constraint("or(multipleOf: 7, multipleOf: 11)")

or

@constraint(OR: [multipleOf: 7, multipleOf: 11])
@confuser
Copy link
Owner

Open for discussion on the or syntax. What example scenarios do you see not covering?

@FluorescentHallucinogen
Copy link
Author

What example scenarios do you see not covering?

E.g.:

@constraint("not(multipleOf: 3)")

or

@constraint("not(startsWith: 'foo')")

or

@constraint("not(endsWith: 'foo')")

Moreover, implementing not makes many rules like notContains unnecessary in favor of not + contains.

@FluorescentHallucinogen
Copy link
Author

Open for discussion on the or syntax.

I propose the syntax similar to the syntax that is used in Prisma: https://www.prisma.io/docs/prisma-graphql-api/reference/queries-qwe1/#combining-multiple-filters.

@FluorescentHallucinogen
Copy link
Author

Custom directives in GraphQL are also combined by AND:

input BookInput {
  title: String! @constraint(minLength: 5) @constraint(format: "email")
}

I was wrong. According to https://facebook.github.io/graphql/June2018/#sec-Directives-Are-Unique-Per-Location, it's not possible to use more than one directive of the same name for the same location.

@confuser
Copy link
Owner

confuser commented Feb 1, 2019

That's interesting, because it's definitely supported within graphql and is the current behaviour

@FluorescentHallucinogen
Copy link
Author

@confuser

because it's definitely supported within graphql and is the current behaviour

See https://github.com/graphql/graphql-js/blob/master/src/validation/rules/UniqueDirectivesPerLocation.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants