Coder Social home page Coder Social logo

bendecoste / gqlgen Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 99designs/gqlgen

0.0 1.0 0.0 5.41 MB

go generate based graphql server library

Home Page: https://gqlgen.com

License: MIT License

Go 97.24% JavaScript 2.16% HTML 0.07% Shell 0.53%

gqlgen's Introduction

gqlgen Continuous Integration 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.

Custom Models

Write a custom model that omits the Friends model:

type User struct {
  ID int
  Name string
}

And reference the model in gqlgen.yml:

# gqlgen.yml
models:
  User:
    model: github.com/you/pkg/model.User # go import path to the User struct above

Explicit Resolvers

If you want to Keep using the generated model: mark the field as requiring a resolver explicitly in gqlgen.yml:

# 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) Friends(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

gqlgen's People

Contributors

andrioid avatar asp24 avatar azavorotnii avatar briskt avatar cfilby avatar codyleyhan avatar creativej avatar dbl-lee avatar edsrzf avatar elgarni avatar gissleh avatar gracenoah avatar hantonelli avatar lwc avatar marwan-at-work avatar mastercactapus avatar mtibben avatar neelance avatar qhenkart avatar richardlindhout avatar sinamt avatar sonatard avatar technoweenie avatar tonyghita avatar vektah avatar vikstrous avatar vvakame avatar yamitzky avatar yudppp avatar zannen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.