Search code examples
graphqlgraphql-java

GraphQL-Java support for complex filters


Does anyone know whether the Java GraphQL implementation (graphql-java) supports complex filters. If I have understood this post correctly:

https://www.graph.cool/docs/tutorials/designing-powerful-apis-with-graphql-query-parameters-aing7uech3/

The reference implementation includes filter argument is a built in argument which supports complex filters with nested conditions. However these examples do not work with the graphql-java examples.

This is the simple example I am playing with using graphql-java:2.3.0:

    GraphQLType employeeType = newObject()
            .name("Employee")
            .field(newFieldDefinition()
                    .name("name")
                    .type(Scalars.GraphQLString)
                    )
            .field(newFieldDefinition()
                    .name("age")
                    .type(Scalars.GraphQLInt)
                    )
            .field(newFieldDefinition()
                    .name("active")
                    .type(Scalars.GraphQLBoolean)
                    )
            .build();

    GraphQLObjectType companyType = newObject()
            .name("Company")
            .field(newFieldDefinition()
                    .name("name")
                    .type(Scalars.GraphQLString)
                    )
            .field(newFieldDefinition()
                    .name("employees")
                    .type(new GraphQLList(employeeType))
                    .argument(newArgument()
                            .name("name")
                            .type(Scalars.GraphQLString)
                            .build()
                    )
                    .argument(newArgument()
                            .name("age")
                            .type(Scalars.GraphQLInt)
                            .build()
                    )
                    .argument(newArgument()
                            .name("active")
                            .type(Scalars.GraphQLBoolean)
                            .build()
                    )
                    .dataFetcher(new EmployeeFetcher())
                    )
            .build();

    GraphQLObjectType companyListType = newObject()
            .name("Companies")
            .field(newFieldDefinition()
                    .name("companies")
                    .type(new GraphQLList(companyType))
                    .argument(newArgument()
                                .name("name")
                                .type(Scalars.GraphQLString)
                                .build()
                            )
                    .dataFetcher(new CompanyFetcher())
                    )
            .build();


    GraphQLSchema schema = GraphQLSchema.newSchema()
            .query(companyListType)
            .build();

    GraphQL graphQL = new GraphQL(schema);

Solution

  • What you're talking about is Graph.cool's extension, not the reference implementation. You can of course build something like that with graphql-java, but there's nothing like it out of the box, as the goal of that lib is to implement the spec only.