Skip to content

Commit

Permalink
<< 99designs:master
Browse files Browse the repository at this point in the history
  • Loading branch information
davladco@cisco.com committed Oct 24, 2021
2 parents d4b43ad + 7db941a commit 06d3cb0
Show file tree
Hide file tree
Showing 358 changed files with 40,608 additions and 2,897 deletions.
10 changes: 0 additions & 10 deletions .github/stale.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/check-fmt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -euo pipefail

go fmt ./...
cd example && go fmt ./...
if [[ $(git --no-pager diff) ]] ; then
echo "you need to run "go fmt" and commit the changes"
git --no-pager diff
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-generate
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euo pipefail

go generate ./...

cd example && go generate ./...
if [[ $(git --no-pager diff) ]] ; then
echo "you need to run "go generate ./..." and commit the changes"
git --no-pager diff
Expand Down
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 -d 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: 0 additions & 8 deletions .github/workflows/check-linting

This file was deleted.

12 changes: 10 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
integration:
runs-on: ubuntu-latest
timeout-minutes: 3
container: golang:1.13-alpine
container: golang:1.17-alpine
steps:
- uses: actions/checkout@v1
- run: apk add --no-cache --no-progress nodejs npm git bash
Expand All @@ -15,10 +15,18 @@ jobs:

federation:
runs-on: ubuntu-latest
container: golang:1.13-alpine
container: golang:1.17-alpine
steps:
- uses: actions/checkout@v1
- run: apk add --no-cache --no-progress nodejs npm git bash
- run: go mod download
- run: cd example/federation ; npm install
- run: .github/workflows/check-federation

init:
runs-on: ubuntu-latest
container: golang:1.17-alpine
steps:
- uses: actions/checkout@v1
- run: apk add --no-cache --no-progress alpine-sdk bash
- run: .github/workflows/check-init
9 changes: 5 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with: { go-version: 1.14 }
with: { go-version: 1.17 }
- run: go mod download
- run: .github/workflows/check-fmt
- run: .github/workflows/check-linting
- run: .github/workflows/check-generate
- name: golangci-lint
uses: golangci/golangci-lint-action@v2

coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2
with: { go-version: 1.14 }
with: { go-version: 1.17 }
- run: go mod download
- run: .github/workflows/check-coverage
env:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
test:
strategy:
matrix:
go: [1.13, 1.14]
go: [1.16, 1.17]
os: [ubuntu-latest, windows-latest]

runs-on: ${{ matrix.os }}
Expand All @@ -14,5 +14,5 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- run: go mod download
- run: go test -race ./...
- run: go mod download && go test -race ./...
- run: cd example && go mod download && go test -race ./...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/codegen/gen
/gen

/.vscode
.idea/
*.test
*.out
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ linters:
- gosimple
- govet
- ineffassign
- interfacer
- misspell
- nakedret
- prealloc
- staticcheck
- structcheck
- typecheck
- unconvert
- unused
- varcheck
Expand Down
55 changes: 55 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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

### Changed

### Fixed


## v0.14.0 - 2021-09-08

### 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)
* Added a new API to finish an already validated config <br />
By [@benjaminjkraft](https://github.com/benjaminjkraft) in [#1387](https://github.com/99designs/gqlgen/pull/1387)

### 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. <br />
By [@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)
* Return introspection document in stable order. <br />
* By [@nyergler](https://github.com/nyergler) in [#1497](https://github.com/99designs/gqlgen/pull/1497)

## v0.13.0 - 2020-09-21

Base version at which changelog was introduced.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Want to contribute to gqlgen? Here are some guidelines for how we accept help.

## Getting in Touch

Our [gitter](https://gitter.im/gqlgen/Lobby) channel is the best place to ask questions or get advice on using gqlgen.
Our [discord](https://discord.gg/DYEq3EMs4U) server is the best place to ask questions or get advice on using gqlgen.

## Reporting Bugs and Issues

Expand Down
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
# 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/) [![GoDoc](https://godoc.org/github.com/99designs/gqlgen?status.svg)](https://godoc.org/github.com/99designs/gqlgen)
![gqlgen](https://user-images.githubusercontent.com/980499/133180111-d064b38c-6eb9-444b-a60f-7005a6e68222.png)

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

# gqlgen [![Integration](https://github.com/99designs/gqlgen/actions/workflows/integration.yml/badge.svg)](https://github.com/99designs/gqlgen/actions) [![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) [![Go Reference](https://pkg.go.dev/badge/github.com/99designs/gqlgen.svg)](https://pkg.go.dev/github.com/99designs/gqlgen) [![Read the Docs](https://badgen.net/badge/docs/available/green)](http://gqlgen.com/)

## What is gqlgen?

[gqlgen](https://github.com/99designs/gqlgen) is a Go library for building GraphQL servers without any fuss.<br/>
[gqlgen](https://github.com/99designs/gqlgen) is a Go library for building GraphQL servers without any fuss.<br/>

- **gqlgen is based on a Schema first approach** — You get to Define your API using the GraphQL [Schema Definition Language](http://graphql.org/learn/schema/).
- **gqlgen prioritizes Type safety** — You should never see `map[string]interface{}` here.
- **gqlgen enables Codegen** — We generate the boring bits, so you can focus on building your app quickly.

Still not convinced enough to use **gqlgen**? Compare **gqlgen** with other Go graphql [implementations](https://gqlgen.com/feature-comparison/)

## Getting Started
- To install gqlgen run the command `go get github.com/99designs/gqlgen` in your project directory.<br/>
- You could initialize a new project using the recommended folder structure by running this command `go run github.com/99designs/gqlgen init`.
## Quick start
1. [Initialise a new go module](https://golang.org/doc/tutorial/create-module)

mkdir example
cd example
go mod init example

2. Add `github.com/99designs/gqlgen` to your [project's tools.go](https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module)

printf '// +build tools\npackage tools\nimport _ "github.com/99designs/gqlgen"' | gofmt > tools.go
go mod tidy

3. Initialise gqlgen config and generate models

go run github.com/99designs/gqlgen init

4. Start the graphql server

go run server.go

You could find a more comprehensive guide to help you get started [here](https://gqlgen.com/getting-started/).<br/>
We also have a couple of real-world [examples](https://github.com/99designs/gqlgen/tree/master/example) that show how to GraphQL applications with **gqlgen** seamlessly,
You can see these [examples](https://github.com/99designs/gqlgen/tree/master/example) here or visit [godoc](https://godoc.org/github.com/99designs/gqlgen).
More help to get started:
- [Getting started tutorial](https://gqlgen.com/getting-started/) - a comprehensive guide to help you get started
- [Real-world examples](https://github.com/99designs/gqlgen/tree/master/example) show how to create GraphQL applications
- [Reference docs](https://pkg.go.dev/github.com/99designs/gqlgen) for the APIs

## Reporting Issues

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
26 changes: 16 additions & 10 deletions api/generate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"fmt"
"syscall"

"github.com/99designs/gqlgen/codegen"
Expand All @@ -9,7 +10,6 @@ import (
"github.com/99designs/gqlgen/plugin/federation"
"github.com/99designs/gqlgen/plugin/modelgen"
"github.com/99designs/gqlgen/plugin/resolvergen"
"github.com/pkg/errors"
)

func Generate(cfg *config.Config, option ...Option) error {
Expand Down Expand Up @@ -40,7 +40,7 @@ func Generate(cfg *config.Config, option ...Option) error {
}

if err := cfg.LoadSchema(); err != nil {
return errors.Wrap(err, "failed to load schema")
return fmt.Errorf("failed to load schema: %w", err)
}

for _, p := range plugins {
Expand All @@ -53,47 +53,53 @@ func Generate(cfg *config.Config, option ...Option) error {

// LoadSchema again now we have everything
if err := cfg.LoadSchema(); err != nil {
return errors.Wrap(err, "failed to load schema")
return fmt.Errorf("failed to load schema: %w", err)
}

if err := cfg.Init(); err != nil {
return errors.Wrap(err, "generating core failed")
return fmt.Errorf("generating core failed: %w", err)
}

for _, p := range plugins {
if mut, ok := p.(plugin.ConfigMutator); ok {
err := mut.MutateConfig(cfg)
if err != nil {
return errors.Wrap(err, p.Name())
return fmt.Errorf("%s: %w", p.Name(), err)
}
}
}
// Merge again now that the generated models have been injected into the typemap
data, err := codegen.BuildData(cfg)
if err != nil {
return errors.Wrap(err, "merging type systems failed")
return fmt.Errorf("merging type systems failed: %w", err)
}

if err = codegen.GenerateCode(data); err != nil {
return errors.Wrap(err, "generating core failed")
return fmt.Errorf("generating core failed: %w", err)
}

if !cfg.SkipModTidy {
if err = cfg.Packages.ModTidy(); err != nil {
return fmt.Errorf("tidy failed: %w", err)
}
}

for _, p := range plugins {
if mut, ok := p.(plugin.CodeGenerator); ok {
err := mut.GenerateCode(data)
if err != nil {
return errors.Wrap(err, p.Name())
return fmt.Errorf("%s: %w", p.Name(), err)
}
}
}

if err = codegen.GenerateCode(data); err != nil {
return errors.Wrap(err, "generating core failed")
return fmt.Errorf("generating core failed: %w", err)
}

if !cfg.SkipValidation {
if err := validate(cfg); err != nil {
return errors.Wrap(err, "validation failed")
return fmt.Errorf("validation failed: %w", err)
}
}

Expand Down
20 changes: 20 additions & 0 deletions api/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,23 @@ func AddPlugin(p plugin.Plugin) Option {
*plugins = append(*plugins, p)
}
}

// ReplacePlugin replaces any existing plugin with a matching plugin name
func ReplacePlugin(p plugin.Plugin) Option {
return func(cfg *config.Config, plugins *[]plugin.Plugin) {
if plugins != nil {
found := false
ps := *plugins
for i, o := range ps {
if p.Name() == o.Name() {
ps[i] = p
found = true
}
}
if !found {
ps = append(ps, p)
}
*plugins = ps
}
}
}
Loading

0 comments on commit 06d3cb0

Please sign in to comment.