yahoo / elide

Elide is a Java library that lets you stand up a GraphQL/JSON-API web service with minimal effort.
https://elide.io
Other
1k stars 229 forks source link

Conflicting grammar between Elide and Native GraphQL filterings? #3213

Closed QubitPi closed 5 months ago

QubitPi commented 6 months ago

Expected Behavior

Hi Elide team, we are trying to fetch a person from database by ID.

We have a working native GraphQL query that looks like

query GetPerson($id:String!) {
  person(filter:$id) {
    edges {
      node {
        id
        name
      }
    }
  }
}

{
  "id": "12345"
}

We expect this query to work in Elide as well

Current Behavior

The query above, however, returns a RSQL parsing error, because it forces us to use RSQL syntax like

query GetPerson() {
  person(filter:"id==\"12345\"") {
    edges {
      node {
        id
        name
      }
    }
  }
}

In addition, variable substitution inside string doesn't seem to work as we was not able to put things like person(filter:"id==${someId}") {

Possible Solution

We have a hack like this

query GetPerson($id:String!) {
  person(filter:$id) {
    edges {
      node {
        id
        name
      }
    }
  }
}

{
  "id": "id=='12345'"
}

But this makes our code non-portable by this non-Graphql syntax: "id": "id=='12345'" at the bottom and we are worried about more such conflicts which would complicate our developments in the future

There would be a much happier Elide user if Elide could transparently maps native GraphQL filtering to Elide's RSQL filtering, because at the end of the day, much more people are comfortable with native GraphQL than adapting a special syntax like RSQL

Steps to Reproduce (for bugs)

The documentation mentions a mandatory grammar of RSQL which aligns with what we see at runtime

Context

We have a frontend project using Apollo GraphQL to construct GraphQL query, specifically using useQuery.

It'd be much better if elide can accept whatever is produced by useQuery

Your Environment

justin-tay commented 5 months ago

As far as I know the GraphQL specification doesn't have any standards regarding the query arguments, let alone the filter argument. Can you indicate where the specification defines this native GraphQL filtering?

I think you would typically manipulate string variables with javascript using template literals.

If you just want to query by id you could use the ids argument.

query GetPerson($ids:[String]) {
  person(ids:$ids) {
    edges {
      node {
        id
        name
      }
    }
  }
}

{
  "ids": ["12345"]
}
QubitPi commented 5 months ago

Hi @justin-tay , thank you for the reply.

Sorry for the confusion. What we mean by "filtering" actually turned out to be "argument". Thanks.

We have tried your query which, however, gives back an error of:

page 2

The data model that gives the error above is:

@Entity
@Table(name = "person")
@Include(rootLevel = true, name = "person", description = "person", friendlyName = "person")
public class Person {

    /**
     * Surrogate key.
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public long id;

    /**
     * The person's legal name.
     */
    public String name;
}
justin-tay commented 5 months ago

Does a person entity with that id exist? If it doesn't exist I think this is the expected behavior.

QubitPi commented 5 months ago

Does a person entity with that id exist? If it doesn't exist I think this is the expected behavior.

That ID doesn't exist yet.

I looked up GraphQL Spec which basically merits what you just said. I will close this issue then.

Thanks, Justin