JetBrains / js-graphql-intellij-plugin

GraphQL language support for WebStorm, IntelliJ IDEA and other IDEs based on the IntelliJ Platform.
https://jimkyndemeyer.github.io/js-graphql-intellij-plugin/
MIT License
880 stars 97 forks source link

Fix deprecated input fields not showing up #715

Closed FrankHeijden closed 2 months ago

FrankHeijden commented 4 months ago

It seems the default introspection query has (includeDeprecated: true) commented out, why was this the case in the first place? It seems the commit that added deprecated fields, included these as comments in the same commit: https://github.com/JetBrains/js-graphql-intellij-plugin/commit/b81990f213472dad552a4d64d53d8bba3fa0b54f

We're having trouble fetching Shopify's GraphQL schema without it, which has a lot of input fields marked as deprecated: https://shopify.dev/docs/api/admin-graphql/2024-07/input-objects/ProductVariantInput#field-productvariantinput-fulfillmentserviceid

vepanimas commented 2 months ago

The reason querying some deprecated fields and arguments is not enabled by default is that they are still in the draft spec of GraphQL, and not every server supports them. I tried making a request with your changes to some public API and received the following response:

{
  "data": null,
  "errors": [
    {
      "message": "Unknown argument \"includeDeprecated\" on field \"args\" of type \"__Directive\".",
      "locations": [
        {
          "line": 13,
          "column": 14
        }
      ]
    },
    {
      "message": "Unknown argument \"includeDeprecated\" on field \"args\" of type \"__Field\".",
      "locations": [
        {
          "line": 28,
          "column": 12
        }
      ]
    },
    {
      "message": "Unknown argument \"includeDeprecated\" on field \"inputFields\" of type \"__Type\".",
      "locations": [
        {
          "line": 37,
          "column": 17
        }
      ]
    },
    {
      "message": "Cannot query field \"isDeprecated\" on type \"__InputValue\".",
      "locations": [
        {
          "line": 59,
          "column": 5
        }
      ]
    },
    {
      "message": "Cannot query field \"deprecationReason\" on type \"__InputValue\".",
      "locations": [
        {
          "line": 60,
          "column": 5
        }
      ]
    }
  ]
}

There is actually a workaround for your case. You can manually define an introspection query in the plugin settings. The UI is poor because it is an advanced option, and I am not sure if it has ever been used before, but it works.

Please, put that query to the Introspection > Query field in the settings:

query IntrospectionQuery {
  __schema {
    queryType { name }
    mutationType { name }
    subscriptionType { name }
    types {
      ...FullType
    }
    directives {
      name
      description
      locations
      args(includeDeprecated: true) {
        ...InputValue
      }
      isRepeatable
    }
  }
}

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

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

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
              }
            }
          }
        }
      }
    }
  }
}

image

vepanimas commented 2 months ago

I created a task WEB-68173 in our issue tracker.