Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mtibben committed Sep 6, 2021
2 parents 269a58a + 023f66d commit cc95717
Show file tree
Hide file tree
Showing 59 changed files with 2,997 additions and 235 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/check-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -euo pipefail

cd example/init

go get github.com/99designs/gqlgen

if { go run github.com/99designs/gqlgen init 2>&1 >&3 3>&- | grep '^' >&2; } 3>&1; then
echo "gqlgen init failed validation"
exit 125
fi
8 changes: 8 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ jobs:
- run: go mod download
- run: cd example/federation ; npm install
- run: .github/workflows/check-federation

init:
runs-on: ubuntu-latest
container: golang:1.16-alpine
steps:
- uses: actions/checkout@v1
- run: apk add --no-cache --no-progress alpine-sdk bash
- run: .github/workflows/check-init
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

* Added a changelog :-) Following the same style as [Apollo Client](https://github.com/apollographql/apollo-client) because that feels like it gives good thanks to the community contributors. <br />
By [@MichaelJCompton](https://github.com/MichaelJCompton) in [#1512](https://github.com/99designs/gqlgen/pull/1512)
* Added support for methods returning `(v, ok)` shaped values to support Prisma Go client. <br />
By [@steebchen](https://github.com/steebchen) in [#1449](https://github.com/99designs/gqlgen/pull/1449)

### Changed

* Updated to gqlparser to v2.2.0. <br />
By [@lwc](https://github.com/lwc) in [#1514](https://github.com/99designs/gqlgen/pull/1514)
* GraphQL playground updated to 1.7.26. <br />
By [@ddouglas](https://github.com/ddouglas) in [#1436](https://github.com/99designs/gqlgen/pull/1436)

### Fixed

* Removed a data race by copying when input fields have default values.
Bu [@skaji](https://github.com/skaji) in [#1456](https://github.com/99designs/gqlgen/pull/1456)
* v0.12.2 broke the handling of pointers to slices by calling the custom Marshal and Unmarshal functions on the entire slice. It now correctly calls the custom Marshal and Unmarshal methods for each element in the slice. <br />
By [@ananyasaxena](https://github.com/ananyasaxena) in [#1363](https://github.com/99designs/gqlgen/pull/1363)
* Changes in go1.16 that mean go.mod and go.sum aren't always up to date. Now `go mod tidy` is run after code generation. <br />
By [@lwc](https://github.com/lwc) in [#1501](https://github.com/99designs/gqlgen/pull/1501)
* Errors in resolving non-nullable arrays were not correctly bubbling up to the next nullable field. <br />
By [@wilhelmeek](https://github.com/wilhelmeek) in [#1480](https://github.com/99designs/gqlgen/pull/1480)
* Fixed a potential deadlock in calling error presenters. <br />
By [@vektah](https://github.com/vektah) in [#1399](https://github.com/99designs/gqlgen/pull/1399)
* Fixed `collectFields` not correctly respecting alias fields in fragments. <br />
By [@vmrajas](https://github.com/vmrajas) in [#1341](https://github.com/99designs/gqlgen/pull/1341)


## [0.13.0] - 2020-09-21

Base version at which changelog was introduced.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# gqlgen [![Continuous Integration](https://github.com/99designs/gqlgen/workflows/Continuous%20Integration/badge.svg)](https://github.com/99designs/gqlgen/actions) [![Read the Docs](https://badgen.net/badge/docs/available/green)](http://gqlgen.com/) [![Go Report Card](https://goreportcard.com/badge/github.com/99designs/gqlgen)](https://goreportcard.com/report/github.com/99designs/gqlgen) [![GoDoc](https://godoc.org/github.com/99designs/gqlgen?status.svg)](https://godoc.org/github.com/99designs/gqlgen)
# gqlgen [![Continuous Integration](https://github.com/99designs/gqlgen/workflows/Continuous%20Integration/badge.svg)](https://github.com/99designs/gqlgen/actions) [![Read the Docs](https://badgen.net/badge/docs/available/green)](http://gqlgen.com/) [![Coverage Status](https://coveralls.io/repos/github/99designs/gqlgen/badge.svg?branch=master)](https://coveralls.io/github/99designs/gqlgen?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/99designs/gqlgen)](https://goreportcard.com/report/github.com/99designs/gqlgen) [![GoDoc](https://godoc.org/github.com/99designs/gqlgen?status.svg)](https://godoc.org/github.com/99designs/gqlgen)

![gqlgen](https://user-images.githubusercontent.com/46195831/89802919-0bb8ef00-db2a-11ea-8ba4-88e7a58b2fd2.png)

Expand Down
4 changes: 2 additions & 2 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Testing generated code is a little tricky, heres how its currently set up.

### Testing responses from a server

There is a server in `codegen/testserver` that is generated as part
There is a server in `codegen/testserver` that is generated as part
of `go generate ./...`, and tests written against it.

There are also a bunch of tests in against the examples, feel free to take examples from there.
Expand All @@ -15,7 +15,7 @@ There are also a bunch of tests in against the examples, feel free to take examp

These tests are **really** slow, because they need to run the whole codegen step. Use them very sparingly. If you can, find a way to unit test it instead.

Take a look at `codegen/input_test.go` for an example.
Take a look at `codegen/testserver/input_test.go` for an example.

### Testing introspection

Expand Down
3 changes: 3 additions & 0 deletions api/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func Generate(cfg *config.Config, option ...Option) error {
if err = codegen.GenerateCode(data); err != nil {
return errors.Wrap(err, "generating core failed")
}
if err = cfg.Packages.ModTidy(); err != nil {
return errors.Wrap(err, "tidy failed")
}

for _, p := range plugins {
if mut, ok := p.(plugin.CodeGenerator); ok {
Expand Down
8 changes: 8 additions & 0 deletions codegen/config/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ func (t *TypeReference) IsSlice() bool {
return t.GQL.Elem != nil && isSlice
}

func (t *TypeReference) IsPtrToSlice() bool {
if t.IsPtr() {
_, isPointerToSlice := t.GO.(*types.Pointer).Elem().(*types.Slice)
return isPointerToSlice
}
return false
}

func (t *TypeReference) IsNamed() bool {
_, isSlice := t.GO.(*types.Named)
return isSlice
Expand Down
3 changes: 3 additions & 0 deletions codegen/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Field struct {
Args []*FieldArgument // A list of arguments to be passed to this field
MethodHasContext bool // If this is bound to a go method, does the method also take a context
NoErr bool // If this is bound to a go method, does that method have an error as the second argument
VOkFunc bool // If this is bound to a go method, is it of shape (interface{}, bool)
Object *Object // A link back to the parent object
Default interface{} // The default value
Stream bool // does this field return a channel?
Expand Down Expand Up @@ -152,6 +153,8 @@ func (b *builder) bindField(obj *Object, f *Field) (errret error) {
sig := target.Type().(*types.Signature)
if sig.Results().Len() == 1 {
f.NoErr = true
} else if s := sig.Results(); s.Len() == 2 && s.At(1).Type().String() == "bool" {
f.VOkFunc = true
} else if sig.Results().Len() != 2 {
return fmt.Errorf("method has wrong number of args")
}
Expand Down
8 changes: 7 additions & 1 deletion codegen/field.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Contex
return nil, fmt.Errorf("unexpected type %T for field %s", v, {{ .Name | quote}})
}
{{- else if .IsMethod -}}
{{- if .NoErr -}}
{{- if .VOkFunc -}}
v, ok := {{.GoReceiverName}}.{{.GoFieldName}}({{ .CallArgs }})
if !ok {
return nil, nil
}
return v, nil
{{- else if .NoErr -}}
return {{.GoReceiverName}}.{{.GoFieldName}}({{ .CallArgs }}), nil
{{- else -}}
return {{.GoReceiverName}}.{{.GoFieldName}}({{ .CallArgs }})
Expand Down
5 changes: 4 additions & 1 deletion codegen/input.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
{{- if not .HasUnmarshal }}
func (ec *executionContext) unmarshalInput{{ .Name }}(ctx context.Context, obj interface{}) ({{.Type | ref}}, error) {
var it {{.Type | ref}}
var asMap = obj.(map[string]interface{})
asMap := map[string]interface{}{}
for k, v := range obj.(map[string]interface{}) {
asMap[k] = v
}
{{ range $field := .Fields}}
{{- if $field.Default}}
if _, present := asMap[{{$field.Name|quote}}] ; !present {
Expand Down
4 changes: 2 additions & 2 deletions codegen/testserver/directive.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ directive @toNull on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | FIELD_DEFINI
directive @directive1 on FIELD_DEFINITION
directive @directive2 on FIELD_DEFINITION
directive @unimplemented on FIELD_DEFINITION
directive @order1(location: String!) on FIELD_DEFINITION | OBJECT
directive @order1(location: String!) repeatable on FIELD_DEFINITION | OBJECT
directive @order2(location: String!) on OBJECT

extend type Query {
Expand Down Expand Up @@ -42,7 +42,7 @@ input InnerDirectives {
message: String! @length(min: 1, message: "not valid")
}

type ObjectDirectives @order1(location: "ObjectDirectives_object_1") @order2(location: "ObjectDirectives_object_2") {
type ObjectDirectives @order1(location: "order1_1") @order1(location: "order1_2") @order2(location: "order2_1") {
text: String! @length(min: 0, max: 7, message: "not valid")
nullableText: String @toNull
order: [String!]!
Expand Down
5 changes: 3 additions & 2 deletions codegen/testserver/directive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,9 @@ func TestDirectives(t *testing.T) {
require.Equal(t, "Ok", resp.DirectiveObject.Text)
require.True(t, resp.DirectiveObject.NullableText == nil)
require.Equal(t, "Query_field", resp.DirectiveObject.Order[0])
require.Equal(t, "ObjectDirectives_object_2", resp.DirectiveObject.Order[1])
require.Equal(t, "ObjectDirectives_object_1", resp.DirectiveObject.Order[2])
require.Equal(t, "order2_1", resp.DirectiveObject.Order[1])
require.Equal(t, "order1_2", resp.DirectiveObject.Order[2])
require.Equal(t, "order1_1", resp.DirectiveObject.Order[3])
})
t.Run("when directive returns nil & custom go field is not nilable", func(t *testing.T) {
var resp struct {
Expand Down
Loading

0 comments on commit cc95717

Please sign in to comment.