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

Filter Implementation #28

Merged
merged 4 commits into from
Sep 11, 2020
Merged

Conversation

ani-sha
Copy link
Member

@ani-sha ani-sha commented Sep 7, 2020

Initial Version - Addition of filtering capabilities #16, few cases are yet to be validated.


public Condition visitIntValue(Value v, org.jooq.Field left, String conditionName) {
Condition c = null;
if(conditionName.equals("eq"))
Copy link
Member

Choose a reason for hiding this comment

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

Amazing job! I see you have all arguments covered. Is that ready for verification?

Copy link
Member Author

Choose a reason for hiding this comment

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

Have to implement in and between for float and int types.

" ) \"accounts\"\n" +
"from PUBLIC.CUSTOMER \"g0\"\n" +
"where (\n" +
" (\n" +
Copy link
Collaborator

Choose a reason for hiding this comment

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

The result of this is not correct. it should be like lastname = 'smith' and firstname='John' and ssn = 'cst01002' a or as enclosing does not mean the attributes inside are separated by or. or is always adjunct operation where you could have said

{
  customers (filter: {
    LASTNAME: {
      eq: "Smith"
    },
    FIRSTNAME: {
      eq: "John"
    },
    or: {
      SSN: {
        eq: "CST01002"
      }
    }
  }
}

which should result in (lastname = 'smith' and firstname='John' ) or ssn = 'cst01002'

overall what I am saying or should not have had any effect on the query above

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing out that, I will correct it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We found ourselves looking at the semantics of or operator recently in Graphback

/cc @craicoverflow if you want to share your experience.

Choose a reason for hiding this comment

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

yeah, We checked out competitors (AppSync) and their query output match that by @rareddy above.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ani-sha did you make sure the previous original test as is should have behaved the way I listed above, as the test is not wrong the results were

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ani-sha keep the test case as is from before, make sure the results were correct.

"from PUBLIC.CUSTOMER \"g0\"\n" +
"where (\n" +
" \"g0\".\"LASTNAME\" like ('%' || replace(\n" +
" replace(\n" +
Copy link
Collaborator

Choose a reason for hiding this comment

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

is JOOQ doing this conversion? seems cryptic, most databases have startsWith and contains kind of functions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree, it's JOOQ. I didn't understand it as well.

@@ -200,7 +188,7 @@ public void startVisitRootObject(Field rootField, GraphQLFieldDefinition rootDef
}

@Override
public void endVisitRootObject(Field rootFeild, GraphQLFieldDefinition rootDefinition, GraphQLObjectType type) {
public void endVisitRootObject(Field rootField, GraphQLFieldDefinition rootDefinition, GraphQLObjectType type) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I need to learn how to spell field, I make this mistake quite often :)

@@ -271,67 +273,130 @@ public void visitArgument(Field field, GraphQLFieldDefinition definition, GraphQ

public Condition visitStringValue(Value v, org.jooq.Field left, String conditionName) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change the parameter Value v' to String` and remove the class castings below. When you are calling this method you already know the type just cast once there. Same for others below too

Condition c = null;
switch (conditionName) {
case "between":
if (v.get(0) instanceof FloatValue)
Copy link
Collaborator

Choose a reason for hiding this comment

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

even they are single line if or for routines wrap them with curly { braces, makes it easier to read the code

for (Value value : v)
list.add(((IntValue) value).getValue());
c = left.in(list);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

put in a default in here and throw a runtimeexception saying wrong condition

break;
case "ge":
c = left.ge(((FloatValue) v).getValue());
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

put in default here and throw a RuntimeException saying wrong condition same at all other similar places.

visitCondition(finalConditionName, condition);
});
for(Object object : field.getValue().getChildren()) {
if(object instanceof ObjectField) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can there be any other value than ObjectField here? if yes capture that in else, you can throw an exception that case

Copy link
Member Author

Choose a reason for hiding this comment

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

Apart from ObjectField, we don't need to create Condition for others we just simply continue.

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

@rareddy rareddy merged commit 13fe624 into graphqlcrud:master Sep 11, 2020
@ani-sha ani-sha deleted the validate-filter branch September 14, 2020 13:35
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.

None yet

5 participants