profusion / sgqlc

Simple GraphQL Client
https://sgqlc.readthedocs.io/
ISC License
506 stars 85 forks source link

Cannot use codegen against server without @include (or against api.github) #191

Closed geekscrapy closed 2 years ago

geekscrapy commented 2 years ago

I tried with a private graphql instance which doesn't have $include directive so it spits out variations of the following error: Unknown directive "@include". I managed to hack at the query to remove these directives and got a schema.

To make sure I was doing it correctly, I tried to replicate the commands in the README however that wasn't successful either. When using the following commands and downloading the SDL from below, I get the following error: validation failed: list index out of range at schema.docs.graphql:1:1

python3 -m sgqlc.introspection --exclude-deprecated --exclude-description -H "Authorization: bearer XXXX" https://api.github.com/graphql github_schema.json
sgqlc-codegen schema github_schema.json github_schema.py
wget https://docs.github.com/public/schema.docs.graphql
sgqlc-codegen operation --schema github_schema.json github_schema sample_operations.py schema.docs.graphql
barbieri commented 2 years ago

could you try running https://github.com/profusion/sgqlc/blob/master/examples/github/update-schema.sh? I just executed it and it's working properly

barbieri commented 2 years ago

btw, the schema.docs.graphql is not an executable document, the sgqlc-codegen operation expects an executable document, see examples:

these are either query, mutation or subscription.

barbieri commented 2 years ago

Last but not least, I never saw a server without @include and @skip because they are listed as recommended in the https://spec.graphql.org/June2018/#sec-Type-System.Directives

GraphQL implementations should provide the @skip and @include directives.

geekscrapy commented 2 years ago

Ahh I think I get it now. Very. Very. Very new to GraphQL!

could you try running https://github.com/profusion/sgqlc/blob/master/examples/github/update-schema.sh? I just executed it and it's working properly

This works fine. It worked ok for me before 👍

btw, the schema.docs.graphql is not an executable document, the sgqlc-codegen operation expects an executable document, see examples:

these are either query, mutation or subscription.

I think I know the use of the .gql file now, so thanks. I missed it as I was reading the DSL demo you have on the README page as part of the previous section (creating the schema) as there is a print of the query :) maybe you could add the filename to the top of that example DSL (sample_operations.gql)?

Last but not least, I never saw a server without @include and @skip because they are listed as recommended in the https://spec.graphql.org/June2018/#sec-Type-System.Directives

GraphQL implementations should provide the @Skip and @include directives.

There's always exceptions 😅 The query I'm running (which works with my server) is below. How much will this break if I use it?! The includes are for convenience for --exclude-deprecated --exclude-description, yes?

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 {
    name
    description
    args {
      ...InputValue
    }
    type {
      ...TypeRef
    }
    isDeprecated
    deprecationReason
  }
  inputFields {
    ...InputValue
  }
  interfaces {
    ...TypeRef
  }
  enumValues {
    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
              }
            }
          }
        }
      }
    }
  }
}
barbieri commented 2 years ago

I think I know the use of the .gql file now, so thanks. I missed it as I was reading the DSL demo you have on the README page as part of the previous section (creating the schema) as there is a print of the query :) maybe you could add the filename to the top of that example DSL (sample_operations.gql)?

Where in the docs you want me to clarify the filename? If you can provide a patch, even better!

There's always exceptions 😅 The query I'm running (which works with my server) is below. How much will this break if I use it?! The includes are for convenience for --exclude-deprecated --exclude-description, yes?

correct, these are to save server and network from useless data, it basically means "do not/do include" that field based on a runtime value, as opposed as to generate a specific query for each. You can use any introspection query and it can include or not the deprecated/descriptions as you wish. Just the structure must be the standard query, as you did.

geekscrapy commented 2 years ago

Where in the docs you want me to clarify the filename? If you can provide a patch, even better!

Smallest ever PR incoming

correct, these are to save server and network from useless data, it basically means "do not/do include" that field based on a runtime value, as opposed as to generate a specific query for each. You can use any introspection query and it can include or not the deprecated/descriptions as you wish. Just the structure must be the standard query, as you did.

Sweet, thanks again

barbieri commented 2 years ago

thank you, it's integrated as #192