From ee95bcfbf8687ae6f07c47f9161f9c9388590704 Mon Sep 17 00:00:00 2001 From: MentatBot <160964065+MentatBot@users.noreply.github.com> Date: Fri, 11 Apr 2025 17:29:07 +0000 Subject: [PATCH] Implement GraphQL Introspection Field and Type System This PR implements the IntrospectionField struct and makes several improvements to the GraphQL introspection type system: 1. Implemented IntrospectionField with all required properties 2. Created TypeRef for consistent type references 3. Updated all collection fields to use slices where appropriate 4. Implemented IntrospectionEnumValue 5. Fixed InputFields in IntrospectionInputObjectType These changes create a more accurate representation of the GraphQL type system for introspection. Closes # 1 --- types/introspection-field.go | 7 ++++ types/introspection-schema.go | 2 +- types/introspection-type.go | 61 +++++++++++++++++++++-------------- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/types/introspection-field.go b/types/introspection-field.go index 8f8c1d4..16b212a 100644 --- a/types/introspection-field.go +++ b/types/introspection-field.go @@ -1,4 +1,11 @@ package types +// IntrospectionField represents a field in a GraphQL object or interface type. type IntrospectionField struct { + Name string `json:"name"` + Description string `json:"description"` + Args []IntrospectionInputValue `json:"args"` + Type IntrospectionInputTypeRef `json:"type"` + IsDeprecated bool `json:"isDeprecated"` + DeprecationReason string `json:"deprecationReason"` } diff --git a/types/introspection-schema.go b/types/introspection-schema.go index 687ebbc..4cd6c28 100644 --- a/types/introspection-schema.go +++ b/types/introspection-schema.go @@ -5,6 +5,6 @@ type IntrospectionSchema struct { QueryType IntrospectionObjectType `json:"queryType"` MutationType IntrospectionObjectType `json:"mutationType"` SubscriptionType IntrospectionObjectType `json:"subscriptionType"` - Types IntrospectionType `json:"types"` + Types []IntrospectionType `json:"types"` Directives []IntrospectionDirective `json:"directives"` } diff --git a/types/introspection-type.go b/types/introspection-type.go index 01b6128..6ddb252 100644 --- a/types/introspection-type.go +++ b/types/introspection-type.go @@ -10,41 +10,54 @@ type IntrospectionScalarType struct { SpecifiedByURL string `json:"specifiedByURL"` } +// TypeRef represents a reference to a type in the schema +type TypeRef struct { + Name string `json:"name"` + Kind string `json:"kind"` +} + type IntrospectionObjectType struct { - Kind string `json:"kind"` - Name string `json:"name"` - Description string `json:"description"` - Fields IntrospectionField `json:"fields"` - Interfaces interface{} `json:"interfaces"` + Kind string `json:"kind"` + Name string `json:"name"` + Description string `json:"description"` + Fields []IntrospectionField `json:"fields"` + Interfaces []TypeRef `json:"interfaces"` } type IntrospectionInterfaceType struct { - Kind string `json:"kind"` - Name string `json:"name"` - Description string `json:"description"` - Fields IntrospectionField `json:"fields"` - Interfaces interface{} `json:"interfaces"` - // possibleTypes IntrospectionObjectType `json:"possibleTypes"` + Kind string `json:"kind"` + Name string `json:"name"` + Description string `json:"description"` + Fields []IntrospectionField `json:"fields"` + Interfaces []TypeRef `json:"interfaces"` + PossibleTypes []TypeRef `json:"possibleTypes"` } type IntrospectionUnionType struct { - Kind string `json:"kind"` - Name string `json:"name"` - Description string `json:"description"` - PossibleTypes IntrospectionObjectType `json:"possibleTypes"` + Kind string `json:"kind"` + Name string `json:"name"` + Description string `json:"description"` + PossibleTypes []TypeRef `json:"possibleTypes"` +} + +type IntrospectionEnumValue struct { + Name string `json:"name"` + Description string `json:"description"` + IsDeprecated bool `json:"isDeprecated"` + DeprecationReason string `json:"deprecationReason"` } type IntrospectionEnumType struct { - Kind string `json:"kind"` - Name string `json:"name"` - Description string `json:"description"` - // enumValues IntrospectionEnumValue `json:"enumValues"` + Kind string `json:"kind"` + Name string `json:"name"` + Description string `json:"description"` + EnumValues []IntrospectionEnumValue `json:"enumValues"` } type IntrospectionInputObjectType struct { - Kind string `json:"kind"` - Name string `json:"name"` - Description string `json:"description"` - // inputFields IntrospectionInputValue `json:"inputFields"` - IsOneOf bool `json:"isOneOf"` + Kind string `json:"kind"` + Name string `json:"name"` + Description string `json:"description"` + InputFields []IntrospectionInputValue `json:"inputFields"` + IsOneOf bool `json:"isOneOf"` }