Skip to content
This repository has been archived by the owner on May 12, 2024. It is now read-only.

Support generating typed filters for async-graphql based on entities #23

Closed
chipsenkbeil opened this issue Jan 4, 2021 · 1 comment
Closed
Milestone

Comments

@chipsenkbeil
Copy link
Owner

Per discussion in async-graphql/async-graphql#373, GraphQL doesn't support unions in input types today. This means that the typed predicates that are unions can't be used directly. Instead, I'll need to be able to generate a unique input type to handle all conditions for a given ent.

enum Predicate {
    Equals(...),
    GreaterThan(...),
}

// becomes

#[derive(async_graphql::InputObject)]
struct Predicate {
    equals: Option<...>,
    greater_than: Option<...>,
}

The challenge is that we'd need to make.a unique struct per type: String, Int, Float, Boolean, and ID. This isn't too demanding and could potentially be converted into a Custom Scalar as it supports maps (BTrees of names and values), lists (vec of values), and other types as defined here: https://github.com/async-graphql/async-graphql/blob/master/value/src/lib.rs#L123

If we can get away with making value be a scalar, then we could make custom predicate & filter input types that flatten the enums into structs of options. We'd want to give them names like GraphQLPredicate and GraphQLFilter (and GraphQLQuery).

In addition, we could still generate unique typed predicates for each of the five standard primitives of GraphQL.

Finally, we could add a derive of EntAsyncGraphQL and EntAsyncGraphQLFilter that would provide an object impl using the async_graphql macro and an input type filter that is a more specific MyEntGraphQLFilter where the edge and field are replaced with the graphql equivalents.

@chipsenkbeil
Copy link
Owner Author

Couple of examples of how filters are done in different implementations supporting GraphQL:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant