Support Go 1.18: Upgrade gqlgen to v0.17.2 (#2443)

* Upgrade gqlgen to v0.17.2

This enables builds on Go 1.18. github.com/vektah/gqlparser is upgraded
to the newest version too.

Getting this to work is a bit of a hazzle. I had to first remove
vendoring from the repository, perform the upgrade and then re-introduce
the vendor directory. I think gqlgens analysis went wrong for some
reason on the upgrade. It would seem a clean-room installation fixed it.

* Bump project to 1.18

* Update all packages, address gqlgenc breaking changes

* Let `go mod tidy` handle the go.mod file

* Upgrade linter to 1.45.2

* Introduce v1.45.2 of the linter

The linter now correctly warns on `strings.Title` because it isn't
unicode-aware. Fix this by using the suggested fix from x/text/cases
to produce unicode-aware strings.

The mapping isn't entirely 1-1 as this new approach has a larger iface:
it spans all of unicode rather than just ASCII. It coincides for ASCII
however, so things should be largely the same.

* Ready ourselves for errchkjson and contextcheck.

* Revert dockerfile golang version changes for now

Co-authored-by: Kermie <kermie@isinthe.house>
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
SmallCoccinelle
2022-04-02 09:08:14 +02:00
committed by GitHub
parent e5c4241180
commit 45f700d6ea
516 changed files with 43496 additions and 10015 deletions

View File

@@ -6,54 +6,84 @@ import (
"github.com/vektah/gqlparser/v2/ast"
)
func ParseIntrospectionQuery(query Query) *ast.SchemaDocument {
func ParseIntrospectionQuery(url string, query Query) *ast.SchemaDocument {
parser := parser{
sharedPosition: &ast.Position{Src: &ast.Source{
Name: "remote",
BuiltIn: false,
}},
}
if url != "" {
parser.sharedPosition.Src.Name = url
}
return parser.parseIntrospectionQuery(query)
}
type parser struct {
sharedPosition *ast.Position
}
func (p parser) parseIntrospectionQuery(query Query) *ast.SchemaDocument {
var doc ast.SchemaDocument
typeMap := query.Schema.Types.NameMap()
doc.Schema = append(doc.Schema, parseSchemaDefinition(query, typeMap))
doc.Schema = append(doc.Schema, p.parseSchemaDefinition(query, typeMap))
doc.Position = p.sharedPosition
for _, typeVale := range typeMap {
doc.Definitions = append(doc.Definitions, parseTypeSystemDefinition(typeVale))
doc.Definitions = append(doc.Definitions, p.parseTypeSystemDefinition(typeVale))
}
for _, directiveValue := range query.Schema.Directives {
doc.Directives = append(doc.Directives, parseDirectiveDefinition(directiveValue))
doc.Directives = append(doc.Directives, p.parseDirectiveDefinition(directiveValue))
}
return &doc
}
func parseSchemaDefinition(query Query, typeMap map[string]*FullType) *ast.SchemaDefinition {
func (p parser) parseSchemaDefinition(query Query, typeMap map[string]*FullType) *ast.SchemaDefinition {
def := ast.SchemaDefinition{}
def.Position = p.sharedPosition
def.OperationTypes = append(def.OperationTypes,
parseOperationTypeDefinitionForQuery(typeMap[*query.Schema.QueryType.Name]),
parseOperationTypeDefinitionForMutation(typeMap[*query.Schema.MutationType.Name]),
)
if query.Schema.QueryType.Name != nil {
def.OperationTypes = append(def.OperationTypes,
p.parseOperationTypeDefinitionForQuery(typeMap[*query.Schema.QueryType.Name]),
)
}
if query.Schema.MutationType != nil {
def.OperationTypes = append(def.OperationTypes,
p.parseOperationTypeDefinitionForMutation(typeMap[*query.Schema.MutationType.Name]),
)
}
return &def
}
func parseOperationTypeDefinitionForQuery(fullType *FullType) *ast.OperationTypeDefinition {
func (p parser) parseOperationTypeDefinitionForQuery(fullType *FullType) *ast.OperationTypeDefinition {
var op ast.OperationTypeDefinition
op.Operation = ast.Query
op.Type = *fullType.Name
op.Position = p.sharedPosition
return &op
}
func parseOperationTypeDefinitionForMutation(fullType *FullType) *ast.OperationTypeDefinition {
func (p parser) parseOperationTypeDefinitionForMutation(fullType *FullType) *ast.OperationTypeDefinition {
var op ast.OperationTypeDefinition
op.Operation = ast.Mutation
op.Type = *fullType.Name
op.Position = p.sharedPosition
return &op
}
func parseDirectiveDefinition(directiveValue *DirectiveType) *ast.DirectiveDefinition {
func (p parser) parseDirectiveDefinition(directiveValue *DirectiveType) *ast.DirectiveDefinition {
args := make(ast.ArgumentDefinitionList, 0, len(directiveValue.Args))
for _, arg := range directiveValue.Args {
argumentDefinition := buildInputValue(arg)
argumentDefinition := p.buildInputValue(arg)
args = append(args, argumentDefinition)
}
locations := make([]ast.DirectiveLocation, 0, len(directiveValue.Locations))
@@ -66,16 +96,17 @@ func parseDirectiveDefinition(directiveValue *DirectiveType) *ast.DirectiveDefin
Name: directiveValue.Name,
Arguments: args,
Locations: locations,
Position: p.sharedPosition,
}
}
func parseObjectFields(typeVale *FullType) ast.FieldList {
func (p parser) parseObjectFields(typeVale *FullType) ast.FieldList {
fieldList := make(ast.FieldList, 0, len(typeVale.Fields))
for _, field := range typeVale.Fields {
typ := getType(&field.Type)
typ := p.getType(&field.Type)
args := make(ast.ArgumentDefinitionList, 0, len(field.Args))
for _, arg := range field.Args {
argumentDefinition := buildInputValue(arg)
argumentDefinition := p.buildInputValue(arg)
args = append(args, argumentDefinition)
}
@@ -84,6 +115,7 @@ func parseObjectFields(typeVale *FullType) ast.FieldList {
Name: field.Name,
Arguments: args,
Type: typ,
Position: p.sharedPosition,
}
fieldList = append(fieldList, fieldDefinition)
}
@@ -91,14 +123,15 @@ func parseObjectFields(typeVale *FullType) ast.FieldList {
return fieldList
}
func parseInputObjectFields(typeVale *FullType) ast.FieldList {
func (p parser) parseInputObjectFields(typeVale *FullType) ast.FieldList {
fieldList := make(ast.FieldList, 0, len(typeVale.InputFields))
for _, field := range typeVale.InputFields {
typ := getType(&field.Type)
typ := p.getType(&field.Type)
fieldDefinition := &ast.FieldDefinition{
Description: pointerString(field.Description),
Name: field.Name,
Type: typ,
Position: p.sharedPosition,
}
fieldList = append(fieldList, fieldDefinition)
}
@@ -106,8 +139,8 @@ func parseInputObjectFields(typeVale *FullType) ast.FieldList {
return fieldList
}
func parseObjectTypeDefinition(typeVale *FullType) *ast.Definition {
fieldList := parseObjectFields(typeVale)
func (p parser) parseObjectTypeDefinition(typeVale *FullType) *ast.Definition {
fieldList := p.parseObjectFields(typeVale)
interfaces := make([]string, 0, len(typeVale.Interfaces))
for _, intf := range typeVale.Interfaces {
interfaces = append(interfaces, pointerString(intf.Name))
@@ -118,6 +151,7 @@ func parseObjectTypeDefinition(typeVale *FullType) *ast.Definition {
enumValue := &ast.EnumValueDefinition{
Description: pointerString(enum.Description),
Name: enum.Name,
Position: p.sharedPosition,
}
enums = append(enums, enumValue)
}
@@ -129,13 +163,13 @@ func parseObjectTypeDefinition(typeVale *FullType) *ast.Definition {
Interfaces: interfaces,
Fields: fieldList,
EnumValues: enums,
Position: nil,
Position: p.sharedPosition,
BuiltIn: true,
}
}
func parseInterfaceTypeDefinition(typeVale *FullType) *ast.Definition {
fieldList := parseObjectFields(typeVale)
func (p parser) parseInterfaceTypeDefinition(typeVale *FullType) *ast.Definition {
fieldList := p.parseObjectFields(typeVale)
interfaces := make([]string, 0, len(typeVale.Interfaces))
for _, intf := range typeVale.Interfaces {
interfaces = append(interfaces, pointerString(intf.Name))
@@ -147,13 +181,13 @@ func parseInterfaceTypeDefinition(typeVale *FullType) *ast.Definition {
Name: pointerString(typeVale.Name),
Interfaces: interfaces,
Fields: fieldList,
Position: nil,
Position: p.sharedPosition,
BuiltIn: true,
}
}
func parseInputObjectTypeDefinition(typeVale *FullType) *ast.Definition {
fieldList := parseInputObjectFields(typeVale)
func (p parser) parseInputObjectTypeDefinition(typeVale *FullType) *ast.Definition {
fieldList := p.parseInputObjectFields(typeVale)
interfaces := make([]string, 0, len(typeVale.Interfaces))
for _, intf := range typeVale.Interfaces {
interfaces = append(interfaces, pointerString(intf.Name))
@@ -165,12 +199,12 @@ func parseInputObjectTypeDefinition(typeVale *FullType) *ast.Definition {
Name: pointerString(typeVale.Name),
Interfaces: interfaces,
Fields: fieldList,
Position: nil,
Position: p.sharedPosition,
BuiltIn: true,
}
}
func parseUnionTypeDefinition(typeVale *FullType) *ast.Definition {
func (p parser) parseUnionTypeDefinition(typeVale *FullType) *ast.Definition {
unions := make([]string, 0, len(typeVale.PossibleTypes))
for _, unionValue := range typeVale.PossibleTypes {
unions = append(unions, *unionValue.Name)
@@ -181,17 +215,18 @@ func parseUnionTypeDefinition(typeVale *FullType) *ast.Definition {
Description: pointerString(typeVale.Description),
Name: pointerString(typeVale.Name),
Types: unions,
Position: nil,
Position: p.sharedPosition,
BuiltIn: true,
}
}
func parseEnumTypeDefinition(typeVale *FullType) *ast.Definition {
func (p parser) parseEnumTypeDefinition(typeVale *FullType) *ast.Definition {
enums := make(ast.EnumValueList, 0, len(typeVale.EnumValues))
for _, enum := range typeVale.EnumValues {
enumValue := &ast.EnumValueDefinition{
Description: pointerString(enum.Description),
Name: enum.Name,
Position: p.sharedPosition,
}
enums = append(enums, enumValue)
}
@@ -201,35 +236,35 @@ func parseEnumTypeDefinition(typeVale *FullType) *ast.Definition {
Description: pointerString(typeVale.Description),
Name: pointerString(typeVale.Name),
EnumValues: enums,
Position: nil,
Position: p.sharedPosition,
BuiltIn: true,
}
}
func parseScalarTypeExtension(typeVale *FullType) *ast.Definition {
func (p parser) parseScalarTypeExtension(typeVale *FullType) *ast.Definition {
return &ast.Definition{
Kind: ast.Scalar,
Description: pointerString(typeVale.Description),
Name: pointerString(typeVale.Name),
Position: nil,
Position: p.sharedPosition,
BuiltIn: true,
}
}
func parseTypeSystemDefinition(typeVale *FullType) *ast.Definition {
func (p parser) parseTypeSystemDefinition(typeVale *FullType) *ast.Definition {
switch typeVale.Kind {
case TypeKindScalar:
return parseScalarTypeExtension(typeVale)
return p.parseScalarTypeExtension(typeVale)
case TypeKindInterface:
return parseInterfaceTypeDefinition(typeVale)
return p.parseInterfaceTypeDefinition(typeVale)
case TypeKindEnum:
return parseEnumTypeDefinition(typeVale)
return p.parseEnumTypeDefinition(typeVale)
case TypeKindUnion:
return parseUnionTypeDefinition(typeVale)
return p.parseUnionTypeDefinition(typeVale)
case TypeKindObject:
return parseObjectTypeDefinition(typeVale)
return p.parseObjectTypeDefinition(typeVale)
case TypeKindInputObject:
return parseInputObjectTypeDefinition(typeVale)
return p.parseInputObjectTypeDefinition(typeVale)
case TypeKindList, TypeKindNonNull:
panic(fmt.Sprintf("not match Kind: %s", typeVale.Kind))
}
@@ -237,6 +272,51 @@ func parseTypeSystemDefinition(typeVale *FullType) *ast.Definition {
panic(fmt.Sprintf("not match Kind: %s", typeVale.Kind))
}
func (p parser) buildInputValue(input *InputValue) *ast.ArgumentDefinition {
typ := p.getType(&input.Type)
var defaultValue *ast.Value
if input.DefaultValue != nil {
defaultValue = &ast.Value{
Raw: pointerString(input.DefaultValue),
Kind: ast.Variable,
Position: p.sharedPosition,
}
}
return &ast.ArgumentDefinition{
Description: pointerString(input.Description),
Name: input.Name,
DefaultValue: defaultValue,
Type: typ,
Position: p.sharedPosition,
}
}
func (p parser) getType(typeRef *TypeRef) *ast.Type {
if typeRef.Kind == TypeKindList {
itemRef := typeRef.OfType
if itemRef == nil {
panic("Decorated type deeper than introspection query.")
}
return ast.ListType(p.getType(itemRef), p.sharedPosition)
}
if typeRef.Kind == TypeKindNonNull {
nullableRef := typeRef.OfType
if nullableRef == nil {
panic("Decorated type deeper than introspection query.")
}
nullableType := p.getType(nullableRef)
nullableType.NonNull = true
return nullableType
}
return ast.NamedType(pointerString(typeRef.Name), p.sharedPosition)
}
func pointerString(s *string) string {
if s == nil {
return ""
@@ -244,46 +324,3 @@ func pointerString(s *string) string {
return *s
}
func buildInputValue(input *InputValue) *ast.ArgumentDefinition {
typ := getType(&input.Type)
var defaultValue *ast.Value
if input.DefaultValue != nil {
defaultValue = &ast.Value{
Raw: pointerString(input.DefaultValue),
Kind: ast.Variable,
}
}
return &ast.ArgumentDefinition{
Description: pointerString(input.Description),
Name: input.Name,
DefaultValue: defaultValue,
Type: typ,
}
}
func getType(typeRef *TypeRef) *ast.Type {
if typeRef.Kind == TypeKindList {
itemRef := typeRef.OfType
if itemRef == nil {
panic("Decorated type deeper than introspection query.")
}
return ast.ListType(getType(itemRef), nil)
}
if typeRef.Kind == TypeKindNonNull {
nullableRef := typeRef.OfType
if nullableRef == nil {
panic("Decorated type deeper than introspection query.")
}
nullableType := getType(nullableRef)
nullableType.NonNull = true
return nullableType
}
return ast.NamedType(pointerString(typeRef.Name), nil)
}