graphql-php icon indicating copy to clipboard operation
graphql-php copied to clipboard

Include aliases in query plan

Open crissi opened this issue 4 years ago • 5 comments

Running lookAhead with queryplan with this query:

$resolveInfo->lookAhead(['group-implementor-fields'])->queryPlan();
query  {
  caseById(id: 7317) {
    default: schemesCount
    closed: schemesCount(status: CLOSED)
    approved: schemesCount(status: APPROVED)
  }
}

Gives us:

{
  "fields": {
    "schemesCount": {
      "type": "Int",
      "fields": [],
      "args": {
        "status": "APPROVED"
      }
    }
  }
}

I suspect all fields should be included somehow in the result!

crissi avatar Feb 16 '22 07:02 crissi

I think the purpose of the query plan is to allow the server to make decisions on how to resolve the query efficiently. Given aliases are given by the client and transparently handled by the execution engine of this library, they do not seem useful to include.

spawnia avatar Feb 16 '22 08:02 spawnia

yes, but since each alias can have different arguments like in my example.

Here it just returns the argument of the last schemesCount property.

crissi avatar Feb 16 '22 10:02 crissi

Right, that is misleading. args should really be a list with multiple args passed to the different aliases - same with fields actually. Perhaps a better structure would be:

{
  "fields": {
    "schemesCount": {
      "type": "Int",
      "aliases": [
        {
          "fields": [],
          "args": {}
        },
        {
          "fields": [],
          "args": {
            "status": "APPROVED"
          }
        },
        {
          "fields": [],
          "args": {
            "status": "CLOSED"
          }
        },
      ]
    }
  }
}

spawnia avatar Feb 16 '22 10:02 spawnia

maybe include the alias name in there for good measure

crissi avatar Feb 16 '22 10:02 crissi

We are having the same issue. We use the queryPlan to dynamically build an ElasticSearch query. Some fields have quite some possible arguments, therefore we want to be able to alias those fields.

Unfortunately, the only alternative for now is duplicating these fields.

jeroenschieven avatar Jan 31 '23 09:01 jeroenschieven