-
Notifications
You must be signed in to change notification settings - Fork 4
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 filter types to schema #21
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package io.graphqlcrud; | ||
|
||
import graphql.Scalars; | ||
import graphql.schema.*; | ||
|
||
public class Filters { | ||
|
||
public static GraphQLInputObjectType.Builder pageInputBuilder() { | ||
return GraphQLInputObjectType.newInputObject().name("PageRequest") | ||
.field(GraphQLInputObjectField.newInputObjectField().name("limit").type(Scalars.GraphQLInt)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("offset").type(Scalars.GraphQLInt)); | ||
} | ||
|
||
public static GraphQLInputObjectType.Builder stringInputBuilder() { | ||
return GraphQLInputObjectType.newInputObject().name("StringInput") | ||
.field(GraphQLInputObjectField.newInputObjectField().name("ne").type(Scalars.GraphQLString)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("eq").type(Scalars.GraphQLString)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("le").type(Scalars.GraphQLString)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("lt").type(Scalars.GraphQLString)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("ge").type(Scalars.GraphQLString)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("gt").type(Scalars.GraphQLString)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("in").type(GraphQLList.list(GraphQLNonNull.nonNull(Scalars.GraphQLString)))) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("contains").type(Scalars.GraphQLString)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("startsWith").type(Scalars.GraphQLString)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("endsWith").type(Scalars.GraphQLString)); | ||
|
||
} | ||
|
||
public static GraphQLInputObjectType.Builder idInputBuilder() { | ||
return GraphQLInputObjectType.newInputObject().name("IDInput") | ||
.field(GraphQLInputObjectField.newInputObjectField().name("ne").type(Scalars.GraphQLID)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("eq").type(Scalars.GraphQLID)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("in").type(GraphQLList.list(GraphQLNonNull.nonNull(Scalars.GraphQLID)))); | ||
|
||
} | ||
|
||
public static GraphQLInputObjectType.Builder booleanInputBuilder() { | ||
return GraphQLInputObjectType.newInputObject().name("BooleanInput") | ||
.field(GraphQLInputObjectField.newInputObjectField().name("ne").type(Scalars.GraphQLBoolean)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("eq").type(Scalars.GraphQLBoolean)); | ||
} | ||
|
||
public static GraphQLInputObjectType.Builder floatInputBuilder() { | ||
return GraphQLInputObjectType.newInputObject().name("FloatInput") | ||
.field(GraphQLInputObjectField.newInputObjectField().name("ne").type(Scalars.GraphQLFloat)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("eq").type(Scalars.GraphQLFloat)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("le").type(Scalars.GraphQLFloat)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("lt").type(Scalars.GraphQLFloat)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("ge").type(Scalars.GraphQLFloat)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("gt").type(Scalars.GraphQLFloat)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("in").type(GraphQLList.list(GraphQLNonNull.nonNull(Scalars.GraphQLFloat)))); | ||
} | ||
|
||
public static GraphQLInputObjectType.Builder intInputBuilder() { | ||
return GraphQLInputObjectType.newInputObject().name("IntInput") | ||
.field(GraphQLInputObjectField.newInputObjectField().name("ne").type(Scalars.GraphQLInt)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("eq").type(Scalars.GraphQLInt)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("le").type(Scalars.GraphQLInt)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("lt").type(Scalars.GraphQLInt)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("ge").type(Scalars.GraphQLInt)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("gt").type(Scalars.GraphQLInt)) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("in").type(GraphQLList.list(GraphQLNonNull.nonNull(Scalars.GraphQLInt)))); | ||
} | ||
|
||
public static GraphQLInputObjectType.Builder orderByInputBuilder() { | ||
return GraphQLInputObjectType.newInputObject().name("OrderByInput") | ||
.field(GraphQLInputObjectField.newInputObjectField().name("field").type(GraphQLNonNull.nonNull(Scalars.GraphQLString))) | ||
.field(GraphQLInputObjectField.newInputObjectField().name("order").type(GraphQLTypeReference.typeRef("SortDirectionEnum")).defaultValue("ASC")); | ||
} | ||
|
||
public static GraphQLEnumType.Builder sortDirectionEnumBuilder() { | ||
return GraphQLEnumType.newEnum().name("SortDirectionEnum") | ||
.value("ASC") | ||
.value("DESC"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. I think it will be amazing to use
https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/schema/idl/SchemaPrinter.java
to print schema for us to verify this under some different model use cases (we can use snapshot testing for this or anything else to validate correctness and call it a day.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are printing the schema using
SchemaPrinter
, once you run you can look for the schema.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running this now! thank you