Skip to content

Apollo Persisted Query Support & the Apollo reference implementation  #2395

Closed

Description

@jregistr

There's an issue at over at the DGS framework: Netflix/dgs-framework#50 for adding support for the PreparsedDocumentProvider. I'd like to take this a bit further and add a module for supporting Apollo Persisted Queries with spring observability in the DGS framework.

I found a few notable details while experimenting with this in the DGS framework and thought I should raise them here.

Apollo Persisted Query support should validate the query hash

The Apollo implementation(and the in-house implementation at NYT) check that the incoming query hash matches the SHA-256 checksum of the query. Ofc this only happens for query register operations, i.e. when both a hash and query are present.

       {
        "query": "{__typename}",
        "extensions":{
         "persistedQuery":{
          "version":1,
          "sha256Hash":"fcf31818e50ac3e818ca4bdbc433d6ab73176f0b9d5f9d5ad17e200cdab6fba4"
        }
      }
    }

If the computed checksum and provided SHA don't match, an error should be thrown indicating so. ApolloPersistedQuerySupport does not do this.

Perhaps this should be a config option to avoid a breaking change? Or also to allow people to choose if they want this.
Here's an example from my experiments last week.

{
  "errors": [
    {
      "message": "provided SHA does not match query",
      "locations": [],
      "extensions": {
        "classification": "BAD_REQUEST"
      }
    }
  ]
}

Nice to have: Throw Persisted Query not supported error

If a client passes APQ to a GraphQL that does not support it, it'd be nice to be able to configure the GraphQL service to throw an error, e.g. requestPipeline.ts#L164.
I'm not sure where I'd put this.

InMemoryPersistedQueryCache that registers incoming queries (less important so likely will drop)

The example InMemoryPersistedQueryCache.java doesn't have a way to push queries into the cache from the request. Would we be open to modify or add a new base impl that does register queries when both a query and hash are present?

That's all. I would really appreciate some feedback, yays or nays. Thank You, have a great day!

Activity

  1. bbakerman commented on Jun 24, 2021

    @bbakerman
    Member

    The ApolloPersistedQuerySupport class was written from a spec and test without an actual consumer.

    So its not production hardened code. Your suggestions of making it better seem spot on. In fact a PR with suggested changes would be perfect!

    If the computed checksum and provided SHA don't match, an error should be thrown indicating so. ApolloPersistedQuerySupport does not do this.

    A PR would be greatly appreciated

    Perhaps this should be a config option to avoid a breaking change? Or also to allow people to choose if they want this.

    I would not have a config option - either just do it by default and perhaps have a protected method so that people could have an alternate implementation if those didnt want this.

    If a client passes APQ to a GraphQL that does not support it, it'd be nice to be able to configure the GraphQL service to throw an error, e.g. requestPipeline.ts#L164.
    I'm not sure where I'd put this.

    This would be best done by a Instrumentation graphql.execution.instrumentation.nextgen.Instrumentation#instrumentExecutionInput or `graphql.execution.instrumentation.nextgen.Instrumentation#beginExecution

    The fact is some one HAS to wire in a graphql.execution.preparsed.persisted.PersistedQuerySupport derived doc provider so you cant have a server that does not support it if they never opted into it. Its not built in like an Apollo Server JS

    The example InMemoryPersistedQueryCache.java doesn't have a way to push queries into the cache from the request. Would we be open to modify or add a new base impl that does register queries when both a query and hash are present?

    I am happy to change it but would every one want that.

    It might well be anther implementation or an option on this one.

    Again a PR would be appreciated.

    We are very open to these being improved

  2. bbakerman commented on Jun 24, 2021

    @bbakerman
    Member

    If a client passes APQ to a GraphQL that does not support it, it'd be nice to be able to configure the GraphQL service to throw an error, e.g. requestPipeline.ts#L164.
    I'm not sure where I'd put this.

    Ahh are you thinking that in DGS you might not know if they want support or not? Is that it?

  3. jregistr commented on Jun 28, 2021

    @jregistr
    ContributorAuthor

    If a client passes APQ to a GraphQL that does not support it, it'd be nice to be able to configure the GraphQL service to throw an error, e.g. requestPipeline.ts#L164.
    I'm not sure where I'd put this.

    Ahh are you thinking that in DGS you might not know if they want support or not? Is that it?

    I was referring to adding such an error to graphql-java. I have seen other graphql implementations that have modules for APQ forgoe this. Such as async-graphql.

  4. added this to the 17.0 milestone on Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions