introspection

package
v0.0.0-...-f795d1e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DirectiveLocationType = &schema.EnumType{
	Name: "__DirectiveLocation",
	Values: map[string]*schema.EnumValueDefinition{
		"QUERY": {
			Value: schema.DirectiveLocationQuery,
		},
		"MUTATION": {
			Value: schema.DirectiveLocationMutation,
		},
		"SUBSCRIPTION": {
			Value: schema.DirectiveLocationSubscription,
		},
		"FIELD": {
			Value: schema.DirectiveLocationField,
		},
		"FRAGMENT_DEFINITION": {
			Value: schema.DirectiveLocationFragmentDefinition,
		},
		"FRAGMENT_SPREAD": {
			Value: schema.DirectiveLocationFragmentSpread,
		},
		"INLINE_FRAGMENT": {
			Value: schema.DirectiveLocationInlineFragment,
		},
		"SCHEMA": {
			Value: schema.DirectiveLocationSchema,
		},
		"SCALAR": {
			Value: schema.DirectiveLocationScalar,
		},
		"OBJECT": {
			Value: schema.DirectiveLocationObject,
		},
		"FIELD_DEFINITION": {
			Value: schema.DirectiveLocationFieldDefinition,
		},
		"ARGUMENT_DEFINITION": {
			Value: schema.DirectiveLocationArgumentDefinition,
		},
		"INTERFACE": {
			Value: schema.DirectiveLocationInterface,
		},
		"UNION": {
			Value: schema.DirectiveLocationUnion,
		},
		"ENUM": {
			Value: schema.DirectiveLocationEnum,
		},
		"ENUM_VALUE": {
			Value: schema.DirectiveLocationEnumValue,
		},
		"INPUT_OBJECT": {
			Value: schema.DirectiveLocationInputObject,
		},
		"INPUT_FIELD_DEFINITION": {
			Value: schema.DirectiveLocationInputFieldDefinition,
		},
	},
}
View Source
var DirectiveType = &schema.ObjectType{
	Name: "__Directive",
	Fields: map[string]*schema.FieldDefinition{
		"name": {
			Type: schema.NewNonNullType(schema.StringType),
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return ctx.Object.(directive).Name, nil
			},
		},
		"description": {
			Type: schema.StringType,
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return nullableString(ctx.Object.(directive).Definition.Description)
			},
		},
		"locations": {
			Type: schema.NewNonNullType(schema.NewListType(schema.NewNonNullType(DirectiveLocationType))),
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return ctx.Object.(directive).Definition.Locations, nil
			},
		},
		"args": {
			Type: schema.NewNonNullType(schema.NewListType(schema.NewNonNullType(InputValueType))),
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return inputValues(ctx.Object.(directive).Definition.Arguments)
			},
		},
	},
}
View Source
var EnumValueType = &schema.ObjectType{
	Name: "__EnumValue",
	Fields: map[string]*schema.FieldDefinition{
		"name": {
			Type: schema.NewNonNullType(schema.StringType),
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return ctx.Object.(enumValue).Name, nil
			},
		},
		"description": {
			Type: schema.StringType,
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return nullableString(ctx.Object.(enumValue).Definition.Description)
			},
		},
		"isDeprecated": {
			Type: schema.NewNonNullType(schema.BooleanType),
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return ctx.Object.(enumValue).Definition.DeprecationReason != "", nil
			},
		},
		"deprecationReason": {
			Type: schema.StringType,
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return nullableString(ctx.Object.(enumValue).Definition.DeprecationReason)
			},
		},
	},
}
View Source
var FieldType = &schema.ObjectType{
	Name: "__Field",
	Fields: map[string]*schema.FieldDefinition{
		"name": {
			Type: schema.NewNonNullType(schema.StringType),
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return ctx.Object.(field).Name, nil
			},
		},
		"description": {
			Type: schema.StringType,
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return nullableString(ctx.Object.(field).Definition.Description)
			},
		},
		"args": {
			Type: schema.NewNonNullType(schema.NewListType(schema.NewNonNullType(InputValueType))),
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return inputValues(ctx.Object.(field).Definition.Arguments)
			},
		},
		"type": {
			Type: schema.NewNonNullType(TypeType),
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return ctx.Object.(field).Definition.Type, nil
			},
		},
		"isDeprecated": {
			Type: schema.NewNonNullType(schema.BooleanType),
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return ctx.Object.(field).Definition.DeprecationReason != "", nil
			},
		},
		"deprecationReason": {
			Type: schema.StringType,
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return nullableString(ctx.Object.(field).Definition.DeprecationReason)
			},
		},
	},
}
View Source
var InputValueType = &schema.ObjectType{
	Name: "__InputValue",
	Fields: map[string]*schema.FieldDefinition{
		"name": {
			Type: schema.NewNonNullType(schema.StringType),
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return ctx.Object.(inputValue).Name, nil
			},
		},
		"description": {
			Type: schema.StringType,
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return nullableString(ctx.Object.(inputValue).Definition.Description)
			},
		},
		"type": {
			Type: schema.NewNonNullType(TypeType),
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return ctx.Object.(inputValue).Definition.Type, nil
			},
		},
		"defaultValue": {
			Type: schema.StringType,
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				def := ctx.Object.(inputValue).Definition
				if v := def.DefaultValue; v != nil {
					return marshalValue(def.Type, v)
				}
				return nil, nil
			},
		},
	},
}
View Source
var MetaFields = map[string]*schema.FieldDefinition{
	"__schema": {
		Type: schema.NewNonNullType(SchemaType),
		Cost: schema.FieldResolverCost(0),
		Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
			return ctx.Schema, nil
		},
	},
	"__type": {
		Type: TypeType,
		Cost: schema.FieldResolverCost(0),
		Arguments: map[string]*schema.InputValueDefinition{
			"name": {
				Type: schema.NewNonNullType(schema.StringType),
			},
		},
		Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
			return ctx.Schema.NamedTypes()[ctx.Arguments["name"].(string)], nil
		},
	},
}
View Source
var NamedTypes = map[string]schema.NamedType{
	"__Schema":            SchemaType,
	"__Type":              TypeType,
	"__Field":             FieldType,
	"__InputValue":        InputValueType,
	"__EnumValue":         EnumValueType,
	"__TypeKind":          TypeKindType,
	"__Directive":         DirectiveType,
	"__DirectiveLocation": DirectiveLocationType,
}
View Source
var Query = []byte(`
    {
      __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
                  }
                }
              }
            }
          }
        }
      }
    }
`)

IntrospectionQuery attempts to query for everything in a schema. The results may be incomplete if there are excessively nested list/non-null types.

View Source
var SchemaType = &schema.ObjectType{
	Name: "__Schema",
	Fields: map[string]*schema.FieldDefinition{
		"types": {
			Type: schema.NewNonNullType(schema.NewListType(schema.NewNonNullType(TypeType))),
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				namedTypes := ctx.Schema.NamedTypes()
				ret := make([]schema.Type, len(namedTypes))
				i := 0
				for _, def := range namedTypes {
					ret[i] = def
					i++
				}
				return ret, nil
			},
		},
		"queryType": {
			Type: schema.NewNonNullType(TypeType),
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return ctx.Schema.QueryType(), nil
			},
		},
		"mutationType": {
			Type: TypeType,
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return ctx.Schema.MutationType(), nil
			},
		},
		"subscriptionType": {
			Type: TypeType,
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				return ctx.Schema.SubscriptionType(), nil
			},
		},
		"directives": {
			Type: schema.NewNonNullType(schema.NewListType(schema.NewNonNullType(DirectiveType))),
			Cost: schema.FieldResolverCost(0),
			Resolve: func(ctx *schema.FieldContext) (interface{}, error) {
				directives := ctx.Schema.Directives()
				ret := make([]directive, len(directives))
				i := 0
				for name, def := range directives {
					ret[i] = directive{
						Name:       name,
						Definition: def,
					}
					i++
				}
				return ret, nil
			},
		},
	},
}
View Source
var TypeKindType = &schema.EnumType{
	Name: "__TypeKind",
	Values: map[string]*schema.EnumValueDefinition{
		"SCALAR": {
			Value: typeKindScalar,
		},
		"OBJECT": {
			Value: typeKindObject,
		},
		"INTERFACE": {
			Value: typeKindInterface,
		},
		"UNION": {
			Value: typeKindUnion,
		},
		"ENUM": {
			Value: typeKindEnum,
		},
		"INPUT_OBJECT": {
			Value: typeKindInputObject,
		},
		"LIST": {
			Value: typeKindList,
		},
		"NON_NULL": {
			Value: typeKindNonNull,
		},
	},
}
View Source
var TypeType = &schema.ObjectType{
	Name: "__Type",
}

Functions

This section is empty.

Types

type DirectiveData

type DirectiveData struct {
	Name        string
	Description string
	Locations   []string
	Args        []InputValueData
}

type EnumValueData

type EnumValueData struct {
	Name              string
	Description       string
	IsDeprecated      bool
	DeprecationReason string
}

type FieldData

type FieldData struct {
	Name              string
	Description       string
	Args              []InputValueData
	Type              TypeData
	IsDeprecated      bool
	DeprecationReason string
}

type InputValueData

type InputValueData struct {
	Name        string
	Description string
	Type        TypeData
}

type SchemaData

type SchemaData struct {
	QueryType        TypeData
	MutationType     *TypeData
	SubscriptionType *TypeData
	Types            []TypeData
	Directives       []DirectiveData
}

func (*SchemaData) GetSchemaDefinition

func (d *SchemaData) GetSchemaDefinition() (*schema.SchemaDefinition, error)

Gets a schema definition for the given schema data. This is not a lossless transformation, and the definition will not be usable for a server as-is, but it can be used for example to validate a query against another server's GraphQL schema.

type TypeData

type TypeData struct {
	Kind          string
	Name          string
	Description   string
	Fields        []FieldData
	InputFields   []InputValueData
	Interfaces    []TypeData
	EnumValues    []EnumValueData
	PossibleTypes []TypeData
	OfType        *TypeData
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL