Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 28 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
version: "2"

run:
timeout: 5m

linters-settings:
gofmt:
simplify: true
govet:
check-shadowing: true
enable-all: true
disable:
- fieldalignment
- deepequalerrors # remove later
formatters:
enable:
Copy link

Copilot AI May 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider enabling the gofumpt linter under "linters.enable" to enforce stricter formatting rules alongside the formatters configuration.

Copilot uses AI. Check for mistakes.
- gofmt
- goimports
- gofumpt
settings:
gofmt:
simplify: true


linters:
disable-all: true
default: none
enable:
- gofmt
- gosimple
- govet
- ineffassign
- exportloopref
- staticcheck
- unconvert
- unused
- misspell
- goimports

issues:
exclude-rules:
- linters:
- unused
path: "graphql_test.go"
exclusions:
rules:
- path: 'graphql_test.go'
linters:
- unused
settings:
govet:
enable-all: true
disable:
- fieldalignment
- deepequalerrors # remove later
enable:
- shadow
unconvert:
fast-math: false
safe: false
2 changes: 1 addition & 1 deletion .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ blocks:
commands:
- sem-version go 1.20
- checkout
- ./scripts/golangci_install.sh -b $(go env GOPATH)/bin v1.51.0
- ./scripts/golangci_install.sh -b $(go env GOPATH)/bin v2.1.6
- export PATH=$(go env GOPATH)/bin:$PATH
- golangci-lint run ./...

Expand Down
12 changes: 6 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
CHANGELOG
# CHANGELOG

[v1.5.0](https://github.com/graph-gophers/graphql-go/releases/tag/v1.5.0) Release v1.5.0

* [FEATURE] Add specifiedBy directive in #532
* [IMPROVEMENT] In this release we improve validation for primitive values, directives, repeat directives, #515, #516, #525, #527
* [IMPROVEMENT] Fix minor unreachable code caused by t.Fatalf #530
* [BUG] Fix __type queries sometimes not returning data in #540
* [BUG] Allow deprecated directive on arguments by @pavelnikolov in #541
* [DOCS] Add array input example #536


[v1.4.0](https://github.com/graph-gophers/graphql-go/releases/tag/v1.4.0) Release v1.4.0
* [FEATURE] Add basic first step for Apollo Federation. This does NOT include full subgraph specification. This PR adds support only for `_service` schema level field. This library is long way from supporting the full sub-graph spec and we do not plan to implement that any time soon.

* [FEATURE] Add basic first step for Apollo Federation. This does NOT include full subgraph specification. This PR adds support only for `_service` schema level field. This library is long way from supporting the full sub-graph spec and we do not plan to implement that any time soon.

[v1.3.0](https://github.com/graph-gophers/graphql-go/releases/tag/v1.3.0) Release v1.3.0

* [FEATURE] Support custom panic handler #468
* [FEATURE] Support interfaces implementing interfaces #471
* [BUG] Support parsing nanoseconds time properly #486
* [BUG] Fix a bug in maxDepth fragment spread logic #492


[v1.2.0](https://github.com/graph-gophers/graphql-go/releases/tag/v1.2.0) Release v1.2.0
* [DOCS] Added examples of how to add JSON map as input scalar type. The goal of this change was to improve documentation #467

* [DOCS] Added examples of how to add JSON map as input scalar type. The goal of this change was to improve documentation #467

[v1.1.0](https://github.com/graph-gophers/graphql-go/releases/tag/v1.1.0) Release v1.1.0

* [FEATURE] Add types package #437
* [FEATURE] Expose `packer.Unmarshaler` as `decode.Unmarshaler` to the public #450
* [FEATURE] Add location fields to type definitions #454
* [FEATURE] `errors.Errorf` preserves original error similar to `fmt.Errorf` #456
* [BUGFIX] Fix duplicated __typename in response (fixes #369) #443


[v1.0.0](https://github.com/graph-gophers/graphql-go/releases/tag/v1.0.0) Initial release
14 changes: 7 additions & 7 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Community Code of Conduct
# Community Code of Conduct

### Contributor Code of Conduct
## Contributor Code of Conduct

As contributors and maintainers of this project, and in the interest of fostering
an open and welcoming community, we pledge to respect all people who contribute
Expand All @@ -9,7 +9,7 @@ submitting pull requests or patches, and other activities.

We are committed to making participation in the GraphQL Go community a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.

## Scope
## Scope

This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.

Expand All @@ -36,17 +36,17 @@ Examples of unacceptable behavior include:
* Other conduct which could reasonably be considered inappropriate in a
professional setting

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct.
By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect
of managing this project.
of managing this project.
Project maintainers who do not follow or enforce the Code of
Conduct may be permanently removed from the project team.

## Reporting
## Reporting

For incidents occurring in the Graph Gophers community, contact @pavelnikolov in [the Gophers Slack](https://gophers.slack.com/) or alternatively you can contact me [at] pavelnikolov [dot] net. You can expect a response within few business days.

## Enforcement
## Enforcement

The Graph Gophers maintainers enforce code of conduct issues for the graphql-go project as well other projects under the graph-gophers github organization.

Expand Down
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Contributing
# Contributing

- With issues:
- Use the search tool before opening a new issue.
Expand All @@ -11,7 +11,7 @@
- It should pass all tests in the available continuous integrations systems such as TravisCI.
- You should add/modify tests to cover your proposed code changes.
- If your pull request contains a new feature, please document it well:
* Consider adding Go executable examples
* Comment all new exported types if outside of the `internal` package
* (optional) Mention it in the README
* Add a comment in the CHANGELOG.md explaining your feature
- Consider adding Go executable examples
- Comment all new exported types if outside of the `internal` package
- (optional) Mention it in the README
- Add a comment in the CHANGELOG.md explaining your feature
9 changes: 5 additions & 4 deletions example/social/social.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ type Resolver struct{}
func (r *Resolver) Admin(ctx context.Context, args struct {
ID string
Role string
}) (*adminResolver, error) {
},
) (*adminResolver, error) {
if usr, ok := usersMap[args.ID]; ok {
if usr.RoleField == args.Role {
return &adminResolver{*usr}, nil
Expand All @@ -212,11 +213,11 @@ func (r *Resolver) Admin(ctx context.Context, args struct {
return nil, err
}

func (r *Resolver) User(ctx context.Context, args struct{ Id string }) (user, error) {
if usr, ok := usersMap[args.Id]; ok {
func (r *Resolver) User(ctx context.Context, args struct{ ID string }) (user, error) {
if usr, ok := usersMap[args.ID]; ok {
return *usr, nil
}
err := fmt.Errorf("user with id=%s does not exist", args.Id)
err := fmt.Errorf("user with id=%s does not exist", args.ID)
return user{}, err
}

Expand Down
3 changes: 2 additions & 1 deletion example/starwars/starwars.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ type MutationResolver struct{}
func (r *MutationResolver) CreateReview(args *struct {
Episode string
Review reviewInput
}) *reviewResolver {
},
) *reviewResolver {
review := &review{
stars: args.Review.Stars,
commentary: args.Review.Commentary,
Expand Down
2 changes: 1 addition & 1 deletion example_custom_err_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (e productNotFoundError) Extensions() map[string]interface{} {

// Example_customErrors demonstrates the use of custom errors and error extensions.
func Example_customErrors() {
var products = []*product{
products := []*product{
{ID: "1000", Name: "Product1"},
{ID: "1001", Name: "Product2"},
}
Expand Down
3 changes: 2 additions & 1 deletion examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ func ExampleMaxQueryLength() {
}

func ExampleRestrictIntrospection() {
allowKey := struct{}{}
type allowKeyType struct{}
allowKey := allowKeyType{}
// only allow introspection if the function below returns true
filter := func(ctx context.Context) bool {
allow, found := ctx.Value(allowKey).(bool)
Expand Down
52 changes: 31 additions & 21 deletions graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3475,12 +3475,15 @@ type childResolver struct{}
func (r *childResolver) TriggerError() (string, error) {
return "This will never be returned to the client", errExample
}

func (r *childResolver) NoError() string {
return "no error"
}

func (r *childResolver) Child() *childResolver {
return &childResolver{}
}

func (r *childResolver) NilChild() *childResolver {
return nil
}
Expand Down Expand Up @@ -4110,12 +4113,12 @@ type nullableResult struct {
Float string
}

type nullableResolver struct {
}
type nullableResolver struct{}

func (r *nullableResolver) TestNullables(args struct {
Input *nullableInput
}) nullableResult {
},
) nullableResult {
var res nullableResult
if args.Input.String.Set {
if args.Input.String.Value == nil {
Expand Down Expand Up @@ -4426,11 +4429,14 @@ func stringsEqual(want, have string) string {
return ""
}

type queryVarResolver struct{}
type filterArgs struct {
Required string
Optional *string
}
type (
queryVarResolver struct{}
filterArgs struct {
Required string
Optional *string
}
)

type filterSearchResults struct {
Match *string
}
Expand Down Expand Up @@ -4494,12 +4500,14 @@ func TestQueryVariablesValidation(t *testing.T) {
}})
}

type interfaceImplementingInterfaceResolver struct{}
type interfaceImplementingInterfaceExample struct {
A string
B string
C bool
}
type (
interfaceImplementingInterfaceResolver struct{}
interfaceImplementingInterfaceExample struct {
A string
B string
C bool
}
)

func (r *interfaceImplementingInterfaceResolver) Hey() *interfaceImplementingInterfaceExample {
return &interfaceImplementingInterfaceExample{
Expand Down Expand Up @@ -4605,13 +4613,15 @@ func TestMaxQueryLength(t *testing.T) {
})
}

type RootResolver struct{}
type QueryResolver struct{}
type MutationResolver struct{}
type SubscriptionResolver struct {
err error
upstream <-chan *helloEventResolver
}
type (
RootResolver struct{}
QueryResolver struct{}
MutationResolver struct{}
SubscriptionResolver struct {
err error
upstream <-chan *helloEventResolver
}
)

func (r *RootResolver) Query() *QueryResolver {
return &QueryResolver{}
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/packer/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func unwrapNonNull(t ast.Type) (ast.Type, bool) {
}

func stripUnderscore(s string) string {
return strings.Replace(s, "_", "", -1)
return strings.ReplaceAll(s, "_", "")
}

// NullUnmarshaller is an unmarshaller that can handle a nil input
Expand Down
11 changes: 6 additions & 5 deletions internal/exec/resolvable/resolvable.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ func makeScalarExec(t *ast.ScalarTypeDefinition, resolverType reflect.Type) (Res
return &Scalar{}, nil
}

func (b *execBuilder) makeObjectExec(typeName string, fields ast.FieldsDefinition, possibleTypes []*ast.ObjectTypeDefinition,
interfaces []*ast.InterfaceTypeDefinition, nonNull bool, resolverType reflect.Type) (*Object, error) {
func (b *execBuilder) makeObjectExec(typeName string, fields ast.FieldsDefinition, possibleTypes []*ast.ObjectTypeDefinition, interfaces []*ast.InterfaceTypeDefinition, nonNull bool, resolverType reflect.Type) (*Object, error) {
if !nonNull {
if resolverType.Kind() != reflect.Ptr && resolverType.Kind() != reflect.Interface {
return nil, fmt.Errorf("%s is not a pointer or interface", resolverType)
Expand Down Expand Up @@ -410,8 +409,10 @@ func (b *execBuilder) makeObjectExec(typeName string, fields ast.FieldsDefinitio
}, nil
}

var contextType = reflect.TypeOf((*context.Context)(nil)).Elem()
var errorType = reflect.TypeOf((*error)(nil)).Elem()
var (
contextType = reflect.TypeOf((*context.Context)(nil)).Elem()
errorType = reflect.TypeOf((*error)(nil)).Elem()
)

func (b *execBuilder) makeFieldExec(typeName string, f *ast.FieldDefinition, m reflect.Method, sf reflect.StructField, methodIndex int, fieldIndex []int, methodHasReceiver bool) (*Field, error) {
var argsPacker *packer.StructPacker
Expand Down Expand Up @@ -588,7 +589,7 @@ func unwrapNonNull(t ast.Type) (ast.Type, bool) {
}

func stripUnderscore(s string) string {
return strings.Replace(s, "_", "", -1)
return strings.ReplaceAll(s, "_", "")
}

func unwrapPtr(t reflect.Type) reflect.Type {
Expand Down
6 changes: 3 additions & 3 deletions internal/exec/selected/selected.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func applySelectionSet(r *Request, s *resolvable.Schema, e *resolvable.Object, s
case "__schema":
if r.AllowIntrospection {
flattenedSels = append(flattenedSels, &SchemaField{
Field: s.Meta.FieldSchema,
Field: s.FieldSchema,
Alias: field.Alias.Name,
Sels: applySelectionSet(r, s, s.Meta.Schema, field.SelectionSet),
Async: true,
Expand All @@ -125,9 +125,9 @@ func applySelectionSet(r *Request, s *resolvable.Schema, e *resolvable.Object, s
}

flattenedSels = append(flattenedSels, &SchemaField{
Field: s.Meta.FieldType,
Field: s.FieldType,
Alias: field.Alias.Name,
Sels: applySelectionSet(r, s, s.Meta.Type, field.SelectionSet),
Sels: applySelectionSet(r, s, s.Type, field.SelectionSet),
Async: true,
FixedResult: reflect.ValueOf(resolvedType),
})
Expand Down
Loading
Loading