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 filter types to schema #21

Merged
merged 4 commits into from
Aug 20, 2020
Merged

Conversation

ani-sha
Copy link
Member

@ani-sha ani-sha commented Aug 13, 2020

Adds types for pagination, ordering and filtering in the schema for #16


GraphQLFieldDefinition fieldDefinition = objectType.getFieldDefinition("customers");
Assertions.assertEquals("page",fieldDefinition.getArguments().get(0).getName());
Assertions.assertEquals("filter", fieldDefinition.getArguments().get(1).getName());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you expand the test to show to full filter and its arguments

.field(GraphQLInputObjectField.newInputObjectField().name("offset").type(Scalars.GraphQLInt));
}

public static GraphQLInputObjectType.Builder filterInputBuilder() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this some form of sandbox. It contains business model where it should be generic?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the schema we read from the Database we are applying the where filters and page limits apply automatically.

@@ -61,9 +53,19 @@ public GraphQLSchema buildSchema(Schema schema) {
GraphQLObjectType.Builder queryTypeBuilder = GraphQLObjectType.newObject();
queryTypeBuilder.name("QueryType");

//add filters for queries
builder.additionalType(Filters.pageInputBuilder().build());
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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

@wtrocki
Copy link
Member

wtrocki commented Aug 17, 2020

Amazing work! Really great use case how easy is to extend the GraphQLJava.
Going to verify this this evening.

return GraphQLInputObjectType.newInputObject().name("QueryFilter")
.field(GraphQLInputObjectField.newInputObjectField().name("id").type(GraphQLTypeReference.typeRef("IDInput")))
.field(GraphQLInputObjectField.newInputObjectField().name("title").type(GraphQLTypeReference.typeRef("StringInput")))
.field(GraphQLInputObjectField.newInputObjectField().name("clickCount").type(GraphQLTypeReference.typeRef("IntInput")))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now using these types add FilterInput on Customer like

CustomerFilterInput {
  SSN StringInput,
  ID    IDInput,
  ...
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding it additionally or modifying the existing type Customer to type CustomerFilterInput?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a separate type, see https://graphqlcrud.org/docs/next/find and example of NoteFilter and also see at the end of the page

Assertions.assertTrue(child.toString().contains("originalType=[QueryFilter]"));
});
}
else if(parent.getKey().equals("FloatInput")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand the test to each individual input type you added. Break them into different methods be more readable.

Assertions.assertTrue(fieldDefinition.getArgument("filter").getType().getChildren().toString().contains("PHONE"));
Assertions.assertTrue(fieldDefinition.getArgument("filter").getType().getChildren().toString().contains("STATE"));
Assertions.assertTrue(fieldDefinition.getArgument("filter").getType().getChildren().toString().contains("SSN"));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant for BoolenInput, IntInput, StringInput.. here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't fetch the types here, as they are TypeReferences to StringInput etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean write test cases for BoolenInput, IntInput, StringInput itself

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look here - engine/src/test/java/io/graphqlcrud/FilterInputTest.java

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, sorry I missed that some how looks good.

Copy link
Collaborator

@rareddy rareddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ani-sha
Copy link
Member Author

ani-sha commented Aug 20, 2020

@wtrocki is it good to land on master?

@wtrocki
Copy link
Member

wtrocki commented Aug 20, 2020

All good to merge. I did not checked last commit. I will run this in the morning from master.

@ani-sha
Copy link
Member Author

ani-sha commented Aug 20, 2020

All good to merge. I did not checked last commit. I will run this in the morning from master.

okay sure!

@ani-sha ani-sha merged commit ff3bb74 into graphqlcrud:master Aug 20, 2020
@ani-sha ani-sha deleted the pagination branch August 31, 2020 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants