Skip to content

Infer operation name when not explicitly given as param

Roy Zwambag requested to merge 414841-infer-operation-name-when-not-given into master

What does this MR do and why?

When calling the graphql api without explicitly providing operationName (which is done by certain libaries, but not all), we did not hit the cache correctly (see #414841 (comment 1430271650)). With this MR we infer the operation name if it is not explicitly given

How to set up and validate locally

Query
query IntrospectionQuery {
  __schema {
    queryType {
      name
    }
    mutationType {
      name
    }
    subscriptionType {
      name
    }
    types {
      ...FullType
    }
    directives {
      name
      description
      locations
      args {
        ...InputValue
      }
    }
  }
}

fragment FullType on __Type {
  kind
  name  
  description
  fields(includeDeprecated: true) {
    name
    description
    args {
      ...InputValue
    }
    type {
      ...TypeRef
    }
    isDeprecated
    deprecationReason
  }
  inputFields {
    ...InputValue
  }
  interfaces {
    ...TypeRef
  }
  enumValues(includeDeprecated: true) {
    name
    description
    isDeprecated
    deprecationReason
  }
  possibleTypes {
    ...TypeRef
  }
}



fragment InputValue on __InputValue {
  name
  description
  type {
    ...TypeRef
  }
  defaultValue
}

fragment TypeRef on __Type {
  kind
  name
  ofType {
    kind
    name
    ofType {
      kind
      name
      ofType {
        kind
        name
        ofType {
          kind
          name
          ofType {
            kind
            name
            ofType {
              kind
              name
              ofType {
                kind
                name
              }
            }
          }
        }
      }
    }
  }
}
  1. Run the above Query twice in http://gdk.test:3000/-/graphql-explorer. It should be cached the second time. This will have the operationName param.
  2. Run the above Query via an API call, without providing operationName. Example for ruby:
require 'httparty'

url = "http://gdk.test:3000/api/graphql"
query = 'query ...'
params = { body: { query: query }}
HTTParty.get(url, params)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #414841 (closed)

Edited by Roy Zwambag

Merge request reports