New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

github.com/iotpanic/gqlgen

Package Overview
Dependencies
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/iotpanic/gqlgen

Source
Go Modules
Version
v0.9.1
Version published
Created
Source

gqlgen CircleCI Read the Docs

What is gqlgen?

gqlgen is a Go library for building GraphQL servers without any fuss. gqlgen is:

  • Schema first — Define your API using the GraphQL Schema Definition Language.
  • Type safe — You should never see map[string]interface{} here.
  • Codegen — Let us generate the boring bits, so you can build your app quickly.

Feature Comparison

Getting Started

First work your way through the Getting Started tutorial.

If you can't find what your looking for, look at our examples for example usage of gqlgen.

Reporting Issues

If you think you've found a bug, or something isn't behaving the way you think it should, please raise an issue on GitHub.

Contributing

Read our Contribution Guidelines for information on how you can help out gqlgen.

Frequently asked questions

How do I prevent fetching child objects that might not be used?

When you have nested or recursive schema like this:

type User {
    id: ID!
    name: String!
    friends: [User!]!
}

You need to tell gqlgen that we should only fetch friends if the user requested it. There are two ways to do this.

  • Write the model yourself and leave off friends.
type User struct {
    Id int
    Name string
}
# gqlgen.yml
models:
  User:
    model: github.com/you/pkg/model.User # go import path to the User struct above
  • Keep using the generated model, and mark the field as requiring a resolver explicitly
# gqlgen.yml
models:
  User:
    fields:
      friends:
        resolver: true # force a resolver to be generated

After doing either of the above and running generate we will need to provide a resolver for friends:

func (r *userResolver) User(ctx context.Context, obj *User) ([]*User, error) {
    // select * from user where friendid = obj.ID
    return friends,  nil
}

IDs are strings but I like ints, why cant I have ints?

You can by remapping it in config:

models:
  ID: # The GraphQL type ID is backed by
    model:
      - github.com/99designs/gqlgen/graphql.IntID  # An go integer
      - github.com/99designs/gqlgen/graphql.ID     # or a go string

This means gqlgen will be able to automatically bind to strings or ints for models you have written yourself, but the first model in this list is used as the default type and it will always be used when:

  • generating models based on schema
  • as arguments in resolvers

There isnt any way around this, gqlgen has no way to know what you want in a given context.

Other Resources

FAQs

Package last updated on 27 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts