pax_global_header 0000666 0000000 0000000 00000000064 15060005047 0014507 g ustar 00root root 0000000 0000000 52 comment=58b43ee9e1920c2a355dbdee114ed15a052bf83a
graphql-go-1.8.0/ 0000775 0000000 0000000 00000000000 15060005047 0013556 5 ustar 00root root 0000000 0000000 graphql-go-1.8.0/.github/ 0000775 0000000 0000000 00000000000 15060005047 0015116 5 ustar 00root root 0000000 0000000 graphql-go-1.8.0/.github/workflows/ 0000775 0000000 0000000 00000000000 15060005047 0017153 5 ustar 00root root 0000000 0000000 graphql-go-1.8.0/.github/workflows/codeql-analysis.yml 0000664 0000000 0000000 00000004432 15060005047 0022771 0 ustar 00root root 0000000 0000000 # For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '16 17 * * 5'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
graphql-go-1.8.0/.github/workflows/go.yml 0000664 0000000 0000000 00000001252 15060005047 0020303 0 ustar 00root root 0000000 0000000 # This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Go
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
pull-requests: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.25
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: v2.4.0
graphql-go-1.8.0/.gitignore 0000664 0000000 0000000 00000000154 15060005047 0015546 0 ustar 00root root 0000000 0000000 /.idea
/.vscode
/internal/validation/testdata/graphql-js
/internal/validation/testdata/node_modules
/vendor
graphql-go-1.8.0/.golangci.yml 0000664 0000000 0000000 00000000745 15060005047 0016150 0 ustar 00root root 0000000 0000000 version: "2"
run:
timeout: 5m
formatters:
enable:
- gofmt
- goimports
- gofumpt
settings:
gofmt:
simplify: true
linters:
default: none
enable:
- govet
- ineffassign
- staticcheck
- unconvert
- unused
- misspell
settings:
govet:
enable-all: true
disable:
- fieldalignment
- deepequalerrors # remove later
enable:
- shadow
unconvert:
fast-math: false
safe: false
graphql-go-1.8.0/CHANGELOG.md 0000664 0000000 0000000 00000010701 15060005047 0015366 0 ustar 00root root 0000000 0000000 # CHANGELOG
[v1.8.0](https://github.com/graph-gophers/graphql-go/releases/tag/v1.8.0) Release v1.8.0
* [FEATURE] Added `DecodeSelectedFieldArgs` helper function to decode argument values for any (nested) selected field path directly from a resolver context, enabling efficient multi-level prefetching without per-resolver argument reflection. This enables selective, multi‑level batching (Category → Products → Reviews) by loading only requested fields, mitigating N+1 issues despite complex filters or pagination.
* [CHORE] Bump Go version in go.mod file to v1.24 to be one minor version less than the latest stable Go release.
[v1.7.2](https://github.com/graph-gophers/graphql-go/releases/tag/v1.7.2) Release v1.7.2
* [BUGFIX] Fix checksum mismatch between direct git access and golang proxy for v1.7.1. This version contains identical functionality to v1.7.1 but with proper tag creation to ensure consistent checksums across all proxy configurations.
[v1.7.1](https://github.com/graph-gophers/graphql-go/releases/tag/v1.7.1) Release v1.7.1
* [IMPROVEMENT] `SelectedFieldNames` now returns dot-delimited nested field paths (e.g. `products`, `products.id`, `products.category`, `products.category.id`). Intermediate container object/list paths are included so resolvers can check for both a branch (`products.category`) and its leaves (`products.category.id`). `HasSelectedField` and `SortedSelectedFieldNames` operate on these paths. This aligns behavior with typical resolver projection needs and fixes missing nested selections.
* [BUGFIX] Reject object, interface, and input object type definitions that declare zero fields/input values (spec compliance).
* [IMPROVEMENT] Optimize overlapping field validation to avoid quadratic memory blowups on large sibling field lists.
* [FEATURE] Add configurable safety valve for overlapping field comparison count with `OverlapValidationLimit(n)` schema option (0 disables the cap). When exceeded validation aborts early with rule `OverlapValidationLimitExceeded`. Disabled by default.
* [TEST] Add benchmarks & randomized overlap stress test for mixed field/fragment patterns.
[v1.7.0](https://github.com/graph-gophers/graphql-go/releases/tag/v1.7.0) Release v1.7.0
* [FEATURE] Add resolver field selection inspection helpers (`SelectedFieldNames`, `HasSelectedField`, `SortedSelectedFieldNames`). Helpers are available by default and compute results lazily only when called. An explicit opt-out (`DisableFieldSelections()` schema option) is provided for applications that want to remove even the minimal context insertion overhead when the helpers are never used.
[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.
[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
[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
graphql-go-1.8.0/CODE_OF_CONDUCT.md 0000664 0000000 0000000 00000005643 15060005047 0016365 0 ustar 00root root 0000000 0000000 # Community 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
through reporting issues, posting feature requests, updating documentation,
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
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
## Our Standards
Examples of behavior that contributes to a positive environment include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* 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.
By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect
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
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
The Graph Gophers maintainers enforce code of conduct issues for the graphql-go project as well other projects under the graph-gophers github organization.
We try to resolve incidents without punishment, but may remove people from the project at our discretion.
## Acknowledgements
This Code of Conduct is adapted from the Contributor Covenant
(http://contributor-covenant.org), version 2.0 available at
http://contributor-covenant.org/version/2/0/code_of_conduct/
graphql-go-1.8.0/CONTRIBUTING.md 0000664 0000000 0000000 00000001503 15060005047 0016006 0 ustar 00root root 0000000 0000000 # Contributing
- With issues:
- Use the search tool before opening a new issue.
- Please provide source code and commit sha if you found a bug.
- Review existing issues and provide feedback or react to them.
- With pull requests:
- Open your pull request against `main`
- Your pull request should have no more than two commits, if not you should squash them.
- 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
graphql-go-1.8.0/LICENSE 0000664 0000000 0000000 00000002417 15060005047 0014567 0 ustar 00root root 0000000 0000000 Copyright (c) 2016 Richard Musiol. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
graphql-go-1.8.0/README.md 0000664 0000000 0000000 00000024210 15060005047 0015034 0 ustar 00root root 0000000 0000000 # graphql-go [](https://sourcegraph.com/github.com/graph-gophers/graphql-go?badge) [](https://github.com/graph-gophers/graphql-go/actions/workflows/go.yml) [](https://goreportcard.com/report/github.com/graph-gophers/graphql-go) [](https://godoc.org/github.com/graph-gophers/graphql-go)

The goal of this project is to provide full support of the [October 2021 GraphQL specification](https://spec.graphql.org/October2021/) with a set of idiomatic, easy to use Go packages.
While still under development (`internal` APIs are almost certainly subject to change), this library is safe for production use.
## Features
- minimal API
- support for `context.Context`
- support for the `OpenTelemetry` and `OpenTracing` standards
- schema type-checking against resolvers
- resolvers are matched to the schema based on method sets (can resolve a GraphQL schema with a Go interface or Go struct).
- handles panics in resolvers
- parallel execution of resolvers
- inspect the selected fields and their args to prefetch data and avoid the N+1 query problem
- subscriptions
- [sample WS transport](https://github.com/graph-gophers/graphql-transport-ws)
## (Some) Documentation [](https://godoc.org/github.com/graph-gophers/graphql-go)
### Getting started
In order to run a simple GraphQL server locally create a `main.go` file with the following content:
```go
package main
import (
"log"
"net/http"
graphql "github.com/graph-gophers/graphql-go"
"github.com/graph-gophers/graphql-go/relay"
)
type query struct{}
func (query) Hello() string { return "Hello, world!" }
func main() {
s := `
type Query {
hello: String!
}
`
schema := graphql.MustParseSchema(s, &query{})
http.Handle("/query", &relay.Handler{Schema: schema})
log.Fatal(http.ListenAndServe(":8080", nil))
}
```
Then run the file with `go run main.go`. To test:
```sh
curl -XPOST -d '{"query": "{ hello }"}' localhost:8080/query
```
For more realistic usecases check our [examples section](https://github.com/graph-gophers/graphql-go/wiki/Examples).
### Resolvers
A resolver must have one method or field for each field of the GraphQL type it resolves. The method or field name has to be [exported](https://golang.org/ref/spec#Exported_identifiers) and match the schema's field's name in a non-case-sensitive way.
You can use struct fields as resolvers by using `SchemaOpt: UseFieldResolvers()`. For example,
```
opts := []graphql.SchemaOpt{graphql.UseFieldResolvers()}
schema := graphql.MustParseSchema(s, &query{}, opts...)
```
When using `UseFieldResolvers` schema option, a struct field will be used *only* when:
- there is no method for a struct field
- a struct field does not implement an interface method
- a struct field does not have arguments
The method has up to two arguments:
- Optional `context.Context` argument.
- Mandatory `*struct { ... }` argument if the corresponding GraphQL field has arguments. The names of the struct fields have to be [exported](https://golang.org/ref/spec#Exported_identifiers) and have to match the names of the GraphQL arguments in a non-case-sensitive way.
The method has up to two results:
- The GraphQL field's value as determined by the resolver.
- Optional `error` result.
Example for a simple resolver method:
```go
func (r *helloWorldResolver) Hello() string {
return "Hello world!"
}
```
The following signature is also allowed:
```go
func (r *helloWorldResolver) Hello(ctx context.Context) (string, error) {
return "Hello world!", nil
}
```
### Separate resolvers for different operations
This feature was released in `v1.6.0`.
The GraphQL specification allows for fields with the same name defined in different query types. For example, the schema below is a valid schema definition:
```graphql
schema {
query: Query
mutation: Mutation
}
type Query {
hello: String!
}
type Mutation {
hello: String!
}
```
The above schema would result in name collision if we use a single resolver struct because fields from both operations correspond to methods in the root resolver (the same Go struct). In order to resolve this issue, the library allows resolvers for query, mutation and subscription operations to be separated using the `Query`, `Mutation` and `Subscription` methods of the root resolver. These special methods are optional and if defined return the resolver for each opeartion. For example, the following is a resolver corresponding to the schema definition above. Note that there is a field named `hello` in both the query and the mutation definitions:
```go
type RootResolver struct{}
type QueryResolver struct{}
type MutationResolver struct{}
func(r *RootResolver) Query() *QueryResolver {
return &QueryResolver{}
}
func(r *RootResolver) Mutation() *MutationResolver {
return &MutationResolver{}
}
func (*QueryResolver) Hello() string {
return "Hello query!"
}
func (*MutationResolver) Hello() string {
return "Hello mutation!"
}
schema := graphql.MustParseSchema(sdl, &RootResolver{}, nil)
...
```
### Schema Options
- `UseStringDescriptions()` enables the usage of double quoted and triple quoted. When this is not enabled, comments are parsed as descriptions instead.
- `UseFieldResolvers()` specifies whether to use struct field resolvers.
- `MaxDepth(n int)` specifies the maximum field nesting depth in a query. The default is 0 which disables max depth checking.
- `MaxParallelism(n int)` specifies the maximum number of resolvers per request allowed to run in parallel. The default is 10.
- `Tracer(tracer trace.Tracer)` is used to trace queries and fields. It defaults to `noop.Tracer`.
- `Logger(logger log.Logger)` is used to log panics during query execution. It defaults to `exec.DefaultLogger`.
- `PanicHandler(panicHandler errors.PanicHandler)` is used to transform panics into errors during query execution. It defaults to `errors.DefaultPanicHandler`.
- `DisableIntrospection()` disables introspection queries.
- `DisableFieldSelections()` disables capturing child field selections used by helper APIs (see below).
- `OverlapValidationLimit(n int)` sets a hard cap on examined overlap pairs during validation; exceeding it emits `OverlapValidationLimitExceeded` error.
### Field Selection Inspection Helpers
Resolvers can introspect which immediate child fields were requested using:
```go
graphql.SelectedFieldNames(ctx) // []string of direct child schema field names
graphql.HasSelectedField(ctx, "name") // bool
graphql.SortedSelectedFieldNames(ctx) // sorted copy
```
Use cases include building projection lists for databases or conditionally avoiding expensive sub-fetches. The helpers are intentionally shallow (only direct children) and fragment spreads / inline fragments are flattened with duplicates removed; meta fields (e.g. `__typename`) are excluded.
Performance: selection data is computed lazily only when a helper is called. If you never call them there is effectively no additional overhead. To remove even the small context value insertion you can opt out with `DisableFieldSelections()`; helpers then return empty results.
For more detail and examples see the [docs](https://godoc.org/github.com/graph-gophers/graphql-go).
### Custom Errors
Errors returned by resolvers can include custom extensions by implementing the `ResolverError` interface:
```go
type ResolverError interface {
error
Extensions() map[string]interface{}
}
```
Example of a simple custom error:
```go
type droidNotFoundError struct {
Code string `json:"code"`
Message string `json:"message"`
}
func (e droidNotFoundError) Error() string {
return fmt.Sprintf("error [%s]: %s", e.Code, e.Message)
}
func (e droidNotFoundError) Extensions() map[string]interface{} {
return map[string]interface{}{
"code": e.Code,
"message": e.Message,
}
}
```
Which could produce a GraphQL error such as:
```go
{
"errors": [
{
"message": "error [NotFound]: This is not the droid you are looking for",
"path": [
"droid"
],
"extensions": {
"code": "NotFound",
"message": "This is not the droid you are looking for"
}
}
],
"data": null
}
```
### Tracing
By default the library uses `noop.Tracer`. If you want to change that you can use the OpenTelemetry or the OpenTracing implementations, respectively:
```go
// OpenTelemetry tracer
package main
import (
"github.com/graph-gophers/graphql-go"
"github.com/graph-gophers/graphql-go/example/starwars"
otelgraphql "github.com/graph-gophers/graphql-go/trace/otel"
"github.com/graph-gophers/graphql-go/trace/tracer"
)
// ...
_, err := graphql.ParseSchema(starwars.Schema, nil, graphql.Tracer(otelgraphql.DefaultTracer()))
// ...
```
Alternatively you can pass an existing trace.Tracer instance:
```go
tr := otel.Tracer("example")
_, err = graphql.ParseSchema(starwars.Schema, nil, graphql.Tracer(&otelgraphql.Tracer{Tracer: tr}))
```
```go
// OpenTracing tracer
package main
import (
"github.com/graph-gophers/graphql-go"
"github.com/graph-gophers/graphql-go/example/starwars"
"github.com/graph-gophers/graphql-go/trace/opentracing"
"github.com/graph-gophers/graphql-go/trace/tracer"
)
// ...
_, err := graphql.ParseSchema(starwars.Schema, nil, graphql.Tracer(opentracing.Tracer{}))
// ...
```
If you need to implement a custom tracer the library would accept any tracer which implements the interface below:
```go
type Tracer interface {
TraceQuery(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, varTypes map[string]*introspection.Type) (context.Context, func([]*errors.QueryError))
TraceField(ctx context.Context, label, typeName, fieldName string, trivial bool, args map[string]interface{}) (context.Context, func(*errors.QueryError))
TraceValidation(context.Context) func([]*errors.QueryError)
}
```
### [Examples](https://github.com/graph-gophers/graphql-go/wiki/Examples)
graphql-go-1.8.0/SECURITY.md 0000664 0000000 0000000 00000001344 15060005047 0015351 0 ustar 00root root 0000000 0000000 # Security Policy
## Supported Versions
We always try to maintain the library secure and suggest our users to upgrade to the latest stable version. We realize that sometimes this is not possible.
| Version | Supported |
| ------- | ------------------ |
| 1.x | :white_check_mark: |
| < 1.0 | :x: |
## MaxDepth
If you are using the `graphql.MaxDepth` schema option, make sure that you upgrade to version v1.3.0 or higher due to a bug causing security vulnerability in earlier versions.
## Reporting a Vulnerability
If you find a security vulnerability with this library, please, DO NOT submit a pull request right away. Please, report the issue to @pavelnikolov in the Gophers Slack in a private message.
graphql-go-1.8.0/ast/ 0000775 0000000 0000000 00000000000 15060005047 0014345 5 ustar 00root root 0000000 0000000 graphql-go-1.8.0/ast/argument.go 0000664 0000000 0000000 00000002443 15060005047 0016521 0 ustar 00root root 0000000 0000000 package ast
// Argument is a representation of the GraphQL Argument.
//
// https://spec.graphql.org/draft/#sec-Language.Arguments
type Argument struct {
Name Ident
Value Value
Directives DirectiveList
}
// ArgumentList is a collection of GraphQL Arguments.
type ArgumentList []*Argument
// Returns a Value in the ArgumentList by name.
func (l ArgumentList) Get(name string) (Value, bool) {
for _, arg := range l {
if arg.Name.Name == name {
return arg.Value, true
}
}
return nil, false
}
// MustGet returns a Value in the ArgumentList by name.
// MustGet will panic if the argument name is not found in the ArgumentList.
func (l ArgumentList) MustGet(name string) Value {
value, ok := l.Get(name)
if !ok {
panic("argument not found")
}
return value
}
type ArgumentsDefinition []*InputValueDefinition
// Get returns an InputValueDefinition in the ArgumentsDefinition by name or nil if not found.
func (a ArgumentsDefinition) Get(name string) *InputValueDefinition {
for _, inputValue := range a {
if inputValue.Name.Name == name {
return inputValue
}
}
return nil
}
// Names returns a slice of ArgumentsDefinition names.
func (a ArgumentsDefinition) Names() []string {
names := make([]string, len(a))
for i, f := range a {
names[i] = f.Name.Name
}
return names
}
graphql-go-1.8.0/ast/directive.go 0000664 0000000 0000000 00000001456 15060005047 0016660 0 ustar 00root root 0000000 0000000 package ast
import "github.com/graph-gophers/graphql-go/errors"
// Directive is a representation of the GraphQL Directive.
//
// http://spec.graphql.org/draft/#sec-Language.Directives
type Directive struct {
Name Ident
Arguments ArgumentList
}
// DirectiveDefinition is a representation of the GraphQL DirectiveDefinition.
//
// http://spec.graphql.org/draft/#sec-Type-System.Directives
type DirectiveDefinition struct {
Name string
Desc string
Repeatable bool
Locations []string
Arguments ArgumentsDefinition
Loc errors.Location
}
type DirectiveList []*Directive
// Returns the Directive in the DirectiveList by name or nil if not found.
func (l DirectiveList) Get(name string) *Directive {
for _, d := range l {
if d.Name.Name == name {
return d
}
}
return nil
}
graphql-go-1.8.0/ast/doc.go 0000664 0000000 0000000 00000000360 15060005047 0015440 0 ustar 00root root 0000000 0000000 /*
Package ast represents all types from the [GraphQL specification] in code.
The names of the Go types, whenever possible, match 1:1 with the names from
the specification.
[GraphQL specification]: https://spec.graphql.org
*/
package ast
graphql-go-1.8.0/ast/enum.go 0000664 0000000 0000000 00000002046 15060005047 0015642 0 ustar 00root root 0000000 0000000 package ast
import "github.com/graph-gophers/graphql-go/errors"
// EnumTypeDefinition defines a set of possible enum values.
//
// Like scalar types, an EnumTypeDefinition also represents a leaf value in a GraphQL type system.
//
// http://spec.graphql.org/draft/#sec-Enums
type EnumTypeDefinition struct {
Name string
EnumValuesDefinition []*EnumValueDefinition
Desc string
Directives DirectiveList
Loc errors.Location
}
// EnumValueDefinition are unique values that may be serialized as a string: the name of the
// represented value.
//
// http://spec.graphql.org/draft/#EnumValueDefinition
type EnumValueDefinition struct {
EnumValue string
Directives DirectiveList
Desc string
Loc errors.Location
}
func (*EnumTypeDefinition) Kind() string { return "ENUM" }
func (t *EnumTypeDefinition) String() string { return t.Name }
func (t *EnumTypeDefinition) TypeName() string { return t.Name }
func (t *EnumTypeDefinition) Description() string { return t.Desc }
graphql-go-1.8.0/ast/extension.go 0000664 0000000 0000000 00000000526 15060005047 0016713 0 ustar 00root root 0000000 0000000 package ast
import "github.com/graph-gophers/graphql-go/errors"
// Extension type defines a GraphQL type extension.
// Schemas, Objects, Inputs and Scalars can be extended.
//
// https://spec.graphql.org/draft/#sec-Type-System-Extensions
type Extension struct {
Type NamedType
Directives DirectiveList
Loc errors.Location
}
graphql-go-1.8.0/ast/field.go 0000664 0000000 0000000 00000001656 15060005047 0015767 0 ustar 00root root 0000000 0000000 package ast
import "github.com/graph-gophers/graphql-go/errors"
// FieldDefinition is a representation of a GraphQL FieldDefinition.
//
// http://spec.graphql.org/draft/#FieldDefinition
type FieldDefinition struct {
Name string
Arguments ArgumentsDefinition
Type Type
Directives DirectiveList
Desc string
Loc errors.Location
}
// FieldsDefinition is a list of an ObjectTypeDefinition's Fields.
//
// https://spec.graphql.org/draft/#FieldsDefinition
type FieldsDefinition []*FieldDefinition
// Get returns a FieldDefinition in a FieldsDefinition by name or nil if not found.
func (l FieldsDefinition) Get(name string) *FieldDefinition {
for _, f := range l {
if f.Name == name {
return f
}
}
return nil
}
// Names returns a slice of FieldDefinition names.
func (l FieldsDefinition) Names() []string {
names := make([]string, len(l))
for i, f := range l {
names[i] = f.Name
}
return names
}
graphql-go-1.8.0/ast/fragment.go 0000664 0000000 0000000 00000002204 15060005047 0016475 0 ustar 00root root 0000000 0000000 package ast
import "github.com/graph-gophers/graphql-go/errors"
type Fragment struct {
On TypeName
Selections SelectionSet
}
// InlineFragment is a representation of the GraphQL InlineFragment.
//
// http://spec.graphql.org/draft/#InlineFragment
type InlineFragment struct {
Fragment
Directives DirectiveList
Loc errors.Location
}
// FragmentDefinition is a representation of the GraphQL FragmentDefinition.
//
// http://spec.graphql.org/draft/#FragmentDefinition
type FragmentDefinition struct {
Fragment
Name Ident
Directives DirectiveList
Loc errors.Location
}
// FragmentSpread is a representation of the GraphQL FragmentSpread.
//
// http://spec.graphql.org/draft/#FragmentSpread
type FragmentSpread struct {
Name Ident
Directives DirectiveList
Loc errors.Location
}
type FragmentList []*FragmentDefinition
// Returns a FragmentDefinition by name or nil if not found.
func (l FragmentList) Get(name string) *FragmentDefinition {
for _, f := range l {
if f.Name.Name == name {
return f
}
}
return nil
}
func (InlineFragment) isSelection() {}
func (FragmentSpread) isSelection() {}
graphql-go-1.8.0/ast/input.go 0000664 0000000 0000000 00000002454 15060005047 0016040 0 ustar 00root root 0000000 0000000 package ast
import "github.com/graph-gophers/graphql-go/errors"
// InputValueDefinition is a representation of the GraphQL InputValueDefinition.
//
// http://spec.graphql.org/draft/#InputValueDefinition
type InputValueDefinition struct {
Name Ident
Type Type
Default Value
Desc string
Directives DirectiveList
Loc errors.Location
TypeLoc errors.Location
}
type InputValueDefinitionList []*InputValueDefinition
// Returns an InputValueDefinition by name or nil if not found.
func (l InputValueDefinitionList) Get(name string) *InputValueDefinition {
for _, v := range l {
if v.Name.Name == name {
return v
}
}
return nil
}
// InputObject types define a set of input fields; the input fields are either scalars, enums, or
// other input objects.
//
// This allows arguments to accept arbitrarily complex structs.
//
// http://spec.graphql.org/draft/#sec-Input-Objects
type InputObject struct {
Name string
Desc string
Values ArgumentsDefinition
Directives DirectiveList
Loc errors.Location
}
func (*InputObject) Kind() string { return "INPUT_OBJECT" }
func (t *InputObject) String() string { return t.Name }
func (t *InputObject) TypeName() string { return t.Name }
func (t *InputObject) Description() string { return t.Desc }
graphql-go-1.8.0/ast/interface.go 0000664 0000000 0000000 00000001676 15060005047 0016646 0 ustar 00root root 0000000 0000000 package ast
import "github.com/graph-gophers/graphql-go/errors"
// InterfaceTypeDefinition recusrively defines list of named fields with their arguments via the
// implementation chain of interfaces.
//
// GraphQL objects can then implement these interfaces which requires that the object type will
// define all fields defined by those interfaces.
//
// http://spec.graphql.org/draft/#sec-Interfaces
type InterfaceTypeDefinition struct {
Name string
PossibleTypes []*ObjectTypeDefinition
Fields FieldsDefinition
Desc string
Directives DirectiveList
Loc errors.Location
Interfaces []*InterfaceTypeDefinition
}
func (*InterfaceTypeDefinition) Kind() string { return "INTERFACE" }
func (t *InterfaceTypeDefinition) String() string { return t.Name }
func (t *InterfaceTypeDefinition) TypeName() string { return t.Name }
func (t *InterfaceTypeDefinition) Description() string { return t.Desc }
graphql-go-1.8.0/ast/object.go 0000664 0000000 0000000 00000001365 15060005047 0016147 0 ustar 00root root 0000000 0000000 package ast
import "github.com/graph-gophers/graphql-go/errors"
// ObjectTypeDefinition represents a GraphQL ObjectTypeDefinition.
//
// type FooObject {
// foo: String
// }
//
// https://spec.graphql.org/draft/#sec-Objects
type ObjectTypeDefinition struct {
Name string
Interfaces []*InterfaceTypeDefinition
Fields FieldsDefinition
Desc string
Directives DirectiveList
InterfaceNames []string
Loc errors.Location
}
func (*ObjectTypeDefinition) Kind() string { return "OBJECT" }
func (t *ObjectTypeDefinition) String() string { return t.Name }
func (t *ObjectTypeDefinition) TypeName() string { return t.Name }
func (t *ObjectTypeDefinition) Description() string { return t.Desc }
graphql-go-1.8.0/ast/query.go 0000664 0000000 0000000 00000002707 15060005047 0016047 0 ustar 00root root 0000000 0000000 package ast
import "github.com/graph-gophers/graphql-go/errors"
// ExecutableDefinition represents a set of operations or fragments that can be executed
// against a schema.
//
// http://spec.graphql.org/draft/#ExecutableDefinition
type ExecutableDefinition struct {
Operations OperationList
Fragments FragmentList
}
// OperationDefinition represents a GraphQL Operation.
//
// https://spec.graphql.org/draft/#sec-Language.Operations
type OperationDefinition struct {
Type OperationType
Name Ident
Vars ArgumentsDefinition
Selections SelectionSet
Directives DirectiveList
Loc errors.Location
}
type OperationType string
// A Selection is a field requested in a GraphQL operation.
//
// http://spec.graphql.org/draft/#Selection
type Selection interface {
isSelection()
}
// A SelectionSet represents a collection of Selections
//
// http://spec.graphql.org/draft/#sec-Selection-Sets
type SelectionSet []Selection
// Field represents a field used in a query.
type Field struct {
Alias Ident
Name Ident
Arguments ArgumentList
Directives DirectiveList
SelectionSet SelectionSet
SelectionSetLoc errors.Location
}
func (Field) isSelection() {}
type OperationList []*OperationDefinition
// Get returns an OperationDefinition by name or nil if not found.
func (l OperationList) Get(name string) *OperationDefinition {
for _, f := range l {
if f.Name.Name == name {
return f
}
}
return nil
}
graphql-go-1.8.0/ast/scalar.go 0000664 0000000 0000000 00000001370 15060005047 0016142 0 ustar 00root root 0000000 0000000 package ast
import "github.com/graph-gophers/graphql-go/errors"
// ScalarTypeDefinition types represent primitive leaf values (e.g. a string or an integer) in a GraphQL type
// system.
//
// GraphQL responses take the form of a hierarchical tree; the leaves on these trees are GraphQL
// scalars.
//
// http://spec.graphql.org/draft/#sec-Scalars
type ScalarTypeDefinition struct {
Name string
Desc string
Directives DirectiveList
Loc errors.Location
}
func (*ScalarTypeDefinition) Kind() string { return "SCALAR" }
func (t *ScalarTypeDefinition) String() string { return t.Name }
func (t *ScalarTypeDefinition) TypeName() string { return t.Name }
func (t *ScalarTypeDefinition) Description() string { return t.Desc }
graphql-go-1.8.0/ast/schema.go 0000664 0000000 0000000 00000005470 15060005047 0016142 0 ustar 00root root 0000000 0000000 package ast
import "github.com/graph-gophers/graphql-go/errors"
// Schema represents a GraphQL service's collective type system capabilities.
// A schema is defined in terms of the types and directives it supports as well as the root
// operation types for each kind of operation: `query`, `mutation`, and `subscription`.
//
// For a more formal definition, read the relevant section in the specification:
//
// http://spec.graphql.org/draft/#sec-Schema
type Schema struct {
// SchemaDefinition corresponds to the `schema` sdl keyword.
SchemaDefinition
// Types are the fundamental unit of any GraphQL schema.
// There are six kinds of named type definitions in GraphQL, and two wrapping types.
//
// http://spec.graphql.org/draft/#sec-Types
Types map[string]NamedType
// Directives are used to annotate various parts of a GraphQL document as an indicator that they
// should be evaluated differently by a validator, executor, or client tool such as a code
// generator.
//
// http://spec.graphql.org/#sec-Type-System.Directives
Directives map[string]*DirectiveDefinition
Objects []*ObjectTypeDefinition
Unions []*Union
Enums []*EnumTypeDefinition
Extensions []*Extension
SchemaString string
}
func (s *Schema) Resolve(name string) Type {
return s.Types[name]
}
// SchemaDefinition is an optional schema block.
// If the schema definition is present it might contain a description and directives. It also contains a map of root operations. For example:
//
// schema {
// query: Query
// mutation: Mutation
// subscription: Subscription
// }
//
// type Query {
// # query fields go here
// }
//
// type Mutation {
// # mutation fields go here
// }
//
// type Subscription {
// # subscription fields go here
// }
//
// If the root operations have default names (i.e. Query, Mutation and Subscription), then the schema definition can be omitted. For example, this is equivalent to the above schema:
//
// type Query {
// # query fields go here
// }
//
// type Mutation {
// # mutation fields go here
// }
//
// type Subscription {
// # subscription fields go here
// }
//
// https://spec.graphql.org/October2021/#sec-Schema
type SchemaDefinition struct {
// Present is true if the schema definition is not omitted, false otherwise. For example, in the following schema
//
// type Query {
// hello: String!
// }
//
// the schema keyword is omitted since the default name for Query is used. In that case Present would be false.
Present bool
// RootOperationTypes determines the place in the type system where `query`, `mutation`, and
// `subscription` operations begin.
//
// http://spec.graphql.org/draft/#sec-Root-Operation-Types
RootOperationTypes map[string]NamedType
EntryPointNames map[string]string
Desc string
Directives DirectiveList
Loc errors.Location
}
graphql-go-1.8.0/ast/types.go 0000664 0000000 0000000 00000003205 15060005047 0016040 0 ustar 00root root 0000000 0000000 package ast
import (
"github.com/graph-gophers/graphql-go/errors"
)
// TypeName is a base building block for GraphQL type references.
type TypeName struct {
Ident
}
// NamedType represents a type with a name.
//
// http://spec.graphql.org/draft/#NamedType
type NamedType interface {
Type
TypeName() string
Description() string
}
type Ident struct {
Name string
Loc errors.Location
}
type Type interface {
// Kind returns one possible GraphQL type kind. A type kind must be
// valid as defined by the GraphQL spec.
//
// https://spec.graphql.org/draft/#sec-Type-Kinds
Kind() string
// String serializes a Type into a GraphQL specification format type.
//
// http://spec.graphql.org/draft/#sec-Serialization-Format
String() string
}
// List represents a GraphQL ListType.
//
// http://spec.graphql.org/draft/#ListType
type List struct {
// OfType represents the inner-type of a List type.
// For example, the List type `[Foo]` has an OfType of Foo.
OfType Type
}
// NonNull represents a GraphQL NonNullType.
//
// https://spec.graphql.org/draft/#NonNullType
type NonNull struct {
// OfType represents the inner-type of a NonNull type.
// For example, the NonNull type `Foo!` has an OfType of Foo.
OfType Type
}
func (*List) Kind() string { return "LIST" }
func (*NonNull) Kind() string { return "NON_NULL" }
func (*TypeName) Kind() string { panic("TypeName needs to be resolved to actual type") }
func (t *List) String() string { return "[" + t.OfType.String() + "]" }
func (t *NonNull) String() string { return t.OfType.String() + "!" }
func (*TypeName) String() string { panic("TypeName needs to be resolved to actual type") }
graphql-go-1.8.0/ast/union.go 0000664 0000000 0000000 00000001505 15060005047 0016025 0 ustar 00root root 0000000 0000000 package ast
import "github.com/graph-gophers/graphql-go/errors"
// Union types represent objects that could be one of a list of GraphQL object types, but provides no
// guaranteed fields between those types.
//
// They also differ from interfaces in that object types declare what interfaces they implement, but
// are not aware of what unions contain them.
//
// http://spec.graphql.org/draft/#sec-Unions
type Union struct {
Name string
UnionMemberTypes []*ObjectTypeDefinition
Desc string
Directives DirectiveList
TypeNames []string
Loc errors.Location
}
func (*Union) Kind() string { return "UNION" }
func (t *Union) String() string { return t.Name }
func (t *Union) TypeName() string { return t.Name }
func (t *Union) Description() string { return t.Desc }
graphql-go-1.8.0/ast/value.go 0000664 0000000 0000000 00000006733 15060005047 0016021 0 ustar 00root root 0000000 0000000 package ast
import (
"strconv"
"strings"
"text/scanner"
"github.com/graph-gophers/graphql-go/errors"
)
// Value represents a literal input or literal default value in the GraphQL Specification.
//
// http://spec.graphql.org/draft/#sec-Input-Values
type Value interface {
// Deserialize transforms a GraphQL specification format literal into a Go type.
Deserialize(vars map[string]interface{}) interface{}
// String serializes a Value into a GraphQL specification format literal.
String() string
Location() errors.Location
}
// PrimitiveValue represents one of the following GraphQL scalars: Int, Float,
// String, or Boolean
type PrimitiveValue struct {
Type rune
Text string
Loc errors.Location
}
func (val *PrimitiveValue) Deserialize(vars map[string]interface{}) interface{} {
switch val.Type {
case scanner.Int:
value, err := strconv.ParseInt(val.Text, 10, 32)
if err != nil {
panic(err)
}
return int32(value)
case scanner.Float:
value, err := strconv.ParseFloat(val.Text, 64)
if err != nil {
panic(err)
}
return value
case scanner.String:
value, err := strconv.Unquote(val.Text)
if err != nil {
panic(err)
}
return value
case scanner.Ident:
switch val.Text {
case "true":
return true
case "false":
return false
default:
return val.Text
}
default:
panic("invalid literal value")
}
}
func (val *PrimitiveValue) String() string { return val.Text }
func (val *PrimitiveValue) Location() errors.Location { return val.Loc }
// ListValue represents a literal list Value in the GraphQL specification.
//
// http://spec.graphql.org/draft/#sec-List-Value
type ListValue struct {
Values []Value
Loc errors.Location
}
func (val *ListValue) Deserialize(vars map[string]interface{}) interface{} {
entries := make([]interface{}, len(val.Values))
for i, entry := range val.Values {
entries[i] = entry.Deserialize(vars)
}
return entries
}
func (val *ListValue) String() string {
entries := make([]string, len(val.Values))
for i, entry := range val.Values {
entries[i] = entry.String()
}
return "[" + strings.Join(entries, ", ") + "]"
}
func (val *ListValue) Location() errors.Location { return val.Loc }
// ObjectValue represents a literal object Value in the GraphQL specification.
//
// http://spec.graphql.org/draft/#sec-Object-Value
type ObjectValue struct {
Fields []*ObjectField
Loc errors.Location
}
// ObjectField represents field/value pairs in a literal ObjectValue.
type ObjectField struct {
Name Ident
Value Value
}
func (val *ObjectValue) Deserialize(vars map[string]interface{}) interface{} {
fields := make(map[string]interface{}, len(val.Fields))
for _, f := range val.Fields {
fields[f.Name.Name] = f.Value.Deserialize(vars)
}
return fields
}
func (val *ObjectValue) String() string {
entries := make([]string, 0, len(val.Fields))
for _, f := range val.Fields {
entries = append(entries, f.Name.Name+": "+f.Value.String())
}
return "{" + strings.Join(entries, ", ") + "}"
}
func (val *ObjectValue) Location() errors.Location {
return val.Loc
}
// NullValue represents a literal `null` Value in the GraphQL specification.
//
// http://spec.graphql.org/draft/#sec-Null-Value
type NullValue struct {
Loc errors.Location
}
func (val *NullValue) Deserialize(vars map[string]interface{}) interface{} { return nil }
func (val *NullValue) String() string { return "null" }
func (val *NullValue) Location() errors.Location { return val.Loc }
graphql-go-1.8.0/ast/variable.go 0000664 0000000 0000000 00000001015 15060005047 0016456 0 ustar 00root root 0000000 0000000 package ast
import "github.com/graph-gophers/graphql-go/errors"
// Variable is used in GraphQL operations to parameterize an input value.
//
// http://spec.graphql.org/draft/#Variable
type Variable struct {
Name string
Loc errors.Location
}
func (v Variable) Deserialize(vars map[string]interface{}) interface{} { return vars[v.Name] }
func (v Variable) String() string { return "$" + v.Name }
func (v *Variable) Location() errors.Location { return v.Loc }
graphql-go-1.8.0/decode/ 0000775 0000000 0000000 00000000000 15060005047 0015001 5 ustar 00root root 0000000 0000000 graphql-go-1.8.0/decode/decode.go 0000664 0000000 0000000 00000000752 15060005047 0016557 0 ustar 00root root 0000000 0000000 package decode
// Unmarshaler defines the api of Go types mapped to custom GraphQL scalar types.
type Unmarshaler interface {
// ImplementsGraphQLType maps the implementing custom Go type
// to the GraphQL scalar type in the schema.
ImplementsGraphQLType(name string) bool
// UnmarshalGraphQL is the custom unmarshaler for the implementing type.
//
// This function will be called whenever you use the
// custom GraphQL scalar type as an input.
UnmarshalGraphQL(input any) error
}
graphql-go-1.8.0/docs/ 0000775 0000000 0000000 00000000000 15060005047 0014506 5 ustar 00root root 0000000 0000000 graphql-go-1.8.0/docs/img/ 0000775 0000000 0000000 00000000000 15060005047 0015262 5 ustar 00root root 0000000 0000000 graphql-go-1.8.0/docs/img/logo.png 0000664 0000000 0000000 00000172177 15060005047 0016747 0 ustar 00root root 0000000 0000000 PNG
IHDR , ʽ sRGB pHYs =iTXtXML:com.adobe.xmp
2018:04:05 21:04:08
2018-03-28T15:56:49-04:00
2018-04-04T21:59:28-04:00
Pixelmator 3.7
adobe:docid:photoshop:5563f4c0-3874-11e8-a9f6-8d6dce19aad7
xmp.did:7c134ef2-c9d9-a04a-8074-010bf2d714fe
xmp.iid:3a473a35-1b61-7548-b8c1-d37321342166
xmp.iid:2cea00a6-7265-0d42-8fa8-49801ffc3443
Adobe Photoshop CC 2017 (Windows)
2018-03-28T15:56:49-04:00
xmp.iid:7c134ef2-c9d9-a04a-8074-010bf2d714fe
created
Adobe Photoshop CC 2017 (Windows)
/
2018-03-28T16:01:58-04:00
xmp.iid:72410e7c-2c06-c54b-aa85-be4234c69957
saved
Adobe Photoshop CC 2017 (Windows)
/
2018-04-04T21:59:28-04:00
xmp.iid:3a473a35-1b61-7548-b8c1-d37321342166
saved
converted
from application/vnd.adobe.photoshop to image/png
derived
converted from application/vnd.adobe.photoshop to image/png
Adobe Photoshop CC 2017 (Windows)
/
2018-04-04T21:59:28-04:00
xmp.iid:2cea00a6-7265-0d42-8fa8-49801ffc3443
saved
adobe:docid:photoshop:ea9698db-3874-11e8-a9f6-8d6dce19aad7
xmp.did:7c134ef2-c9d9-a04a-8074-010bf2d714fe
300
229
1
image/png
72
5
2
1
72
sRGB IEC61966-2.1
adobe:docid:photoshop:a6ba20b8-337c-11e8-9a61-a538f610f253
xmp.did:ac00a4cc-1034-4276-87d5-15fd99ebc41b
3
(Q @ IDATx]ˑK3 9IߏbF>bYTD%$|䜹zoٙݻ#+=vBOOOOOuU*?2B۷4QQQ#q?)++vhhhի~ᇩ?ca4Ҋ@zys1Ȥի(55.ϯƅOO>>MS<((ʕ+ܽ{w;^b*zJ_~yH0`