cloudy-sky-software / pulschema

Pul(umi) schema from API specs
https://buttondown.email/css-blog/archive/create-a-pulumi-provider-from-openapi-spec/
Other
18 stars 2 forks source link

Supporting GraphQL schemas #82

Open praneetloke opened 1 year ago

praneetloke commented 1 year ago

Some cloud providers only support GraphQL for their public API. It would be good to understand how we can use GraphQL introspection to gather information CRUD operations for resources.

praneetloke commented 1 year ago

The following introspection query allows us to fetch mutations (substitute mutationType for queryType for queries) and their return types. Since GraphQL does not have HTTP verbs, we'll have to use the operation name as a hint for what type of operation a certain query will perform in the backend. For example, createXYZ or deleteXYZ is for creating and deleting a type called XYZ.

{
  __schema {
    mutationType {
      fields {
        name
        description
        type {
          ofType {
            name
            kind
            ofType{
              name
              kind
              ofType{
                name
                kind
              }
            }
          }
        }
      }
    }
  }
}
praneetloke commented 1 year ago

And this query returns all types along with their fields:

{
  __schema {
    types {
      name
      fields {
        description
        deprecationReason
        name
        type {
          name
          ofType{
            kind
            name
            ofType{
              kind
              name
            }
          }
        }
      }
    }
  }
}