https://github.com/sungam3r/graphql-introspection-model
Types for GraphQL introspection model.
https://github.com/sungam3r/graphql-introspection-model
graphql introspection
Last synced: 20 days ago
JSON representation
Types for GraphQL introspection model.
- Host: GitHub
- URL: https://github.com/sungam3r/graphql-introspection-model
- Owner: sungam3r
- License: mit
- Created: 2019-12-09T11:05:24.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-03-03T18:40:32.000Z (2 months ago)
- Last Synced: 2025-04-12T18:12:46.322Z (20 days ago)
- Topics: graphql, introspection
- Language: C#
- Homepage:
- Size: 294 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# graphql-introspection-model

[](https://codecov.io/gh/sungam3r/graphql-introspection-model)
[](https://www.nuget.org/packages/GraphQL.IntrospectionModel)
[](https://www.nuget.org/packages/GraphQL.IntrospectionModel)[](https://github.com/sungam3r/graphql-introspection-model/releases)
[](https://github.com/sungam3r/graphql-introspection-model/commits/master)
[](https://github.com/sungam3r/graphql-introspection-model/graphs/contributors)


[](https://github.com/sungam3r/graphql-introspection-model/actions/workflows/test.yml)
[](https://github.com/sungam3r/graphql-introspection-model/actions/workflows/publish-preview.yml)
[](https://github.com/sungam3r/graphql-introspection-model/actions/workflows/publish-release.yml)
[](https://github.com/sungam3r/graphql-introspection-model/actions/workflows/codeql-analysis.yml)Types for GraphQL [introspection](https://graphql.github.io/graphql-spec/October2021/#sec-Introspection) model. Used by [graphql-sdl-exporter](https://github.com/sungam3r/graphql-sdl-exporter).
A GraphQL server supports introspection over its schema. This schema is queried using GraphQL itself, creating a powerful
platform for tool‐building.Here's what a "classic" introspection query looks like:
```graphql
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
}
}
}
}
}
}
}
}
```The result of this query (like all other GraphQL queries) is JSON. You can deal with it directly or deserialize it into some data structures.
Such data structures are provided by this repository. The top level type is [`GraphQLResponse`](src/GraphQL.IntrospectionModel/GraphQLResponse.cs).
After deserialization JSON into the `GraphQLResponse` (or after creating `GraphQLSchema` in any other way), it can be transformed into AST
representation and then printed by `SDLPrinter` from [GraphQL-Parser](https://github.com/graphql-dotnet/parser) nuget package.#### Example of deserializing introspection response
```csharp
using System.Text.Json;string text = ...; // from HTTP introspection response
var response = JsonSerializer.Deserialize(text, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
Converters = { new JsonStringEnumConverter() }
});
var schema = response.Data.__Schema; // note that Data may be null, so check response.Errors
```#### Example of printing `GraphQLSchema` into SDL
```csharp
GraphQLSchema schema = ...;var converter = new ASTConverter();
var document = converter.ToDocument(schema);
var printer = new SDLPrinter(options);
var sdl = printer.Print(document);// or use one-line extension method
var sdl = schema.Print();
```GraphQL has its own language to write GraphQL schemas, [SDL](https://graphql.github.io/graphql-spec/October2021/#sec-Type-System) - Schema Definition Language.
SDL is simple and intuitive to use while being extremely powerful and expressive. Some examples of SDL documents can be found in [graphql-sdl-exporter](https://github.com/sungam3r/graphql-sdl-exporter/tree/master/samples) project.Many types in this project implement the [`IHasDirectives`](src/GraphQL.IntrospectionModel/IHasDirectives.cs) interface. It serves to obtain information
about the directives applied to the element. The [official specification](https://graphql.github.io/graphql-spec/October2021) does not describe such a possibility,
although [discussions](https://github.com/graphql/graphql-spec/issues/300) are underway to expand the specification to add this feature.
[graphql-sdl-exporter](https://github.com/sungam3r/graphql-sdl-exporter/tree/master/samples) can get information about directives if the server
supports this feature.#### Variations of introspection query
This repo provides 4 variations of [introspection query](src/GraphQL.IntrospectionModel/IntrospectionQuery.cs):
1. **Classic** - "classic" introspection query provided above (without exposing applied directives).
It conforms to the latest release version of the spec.2) **ClassicDraft** - the same as "classic" + deprecations for input values.
See [PR](https://github.com/graphql/graphql-spec/pull/805) for more info. It conforms to the prerelease
(working draft) version of the spec.3) **Modern** - modified "classic" introspection query, in which the directives applied to the schema
elements are exposed. It requires GraphQL server to support this feature.
See [GraphQL.NET](https://graphql-dotnet.github.io/docs/getting-started/directives/#directives-and-introspection)
as an example of such a server.4) **ModernDraft** - the same as "modern" + deprecations for input values. This is the most advanced
query among all available.