All Projects → 99designs → Gqlgen

99designs / Gqlgen

Licence: mit
go generate based graphql server library

Programming Languages

go
31211 projects - #10 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Gqlgen

Graphql Codegen Hasura
code-generator plugins for hasura/apollo-gql/typescript development
Stars: ✭ 113 (-98.36%)
Mutual labels:  graphql, codegen
Graphql Typed Client
A tool that generates a strongly typed client library for any GraphQL endpoint. The client allows writing GraphQL queries as plain JS objects (with type safety, awesome code completion experience, custom scalar type mapping, type guards and more)
Stars: ✭ 194 (-97.18%)
Mutual labels:  graphql, codegen
Dataloader
DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a consistent API over various backends and reduce requests to those backends via batching and caching.
Stars: ✭ 11,040 (+60.47%)
Mutual labels:  graphql, dataloader
Hype Beats
Real-time Collaborative Beatbox with React & GraphQL
Stars: ✭ 100 (-98.55%)
Mutual labels:  graphql, subscriptions
Graphaello
A Tool for Writing Declarative, Type-Safe and Data-Driven Applications in SwiftUI using GraphQL
Stars: ✭ 355 (-94.84%)
Mutual labels:  graphql, codegen
Superlifter
A DataLoader for Clojure/script
Stars: ✭ 102 (-98.52%)
Mutual labels:  graphql, dataloader
Hotchocolate
Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
Stars: ✭ 3,009 (-56.26%)
Mutual labels:  graphql, dataloader
Subscriptions Transport Sse
A Server-Side-Events (SSE) client + server for GraphQL subscriptions
Stars: ✭ 55 (-99.2%)
Mutual labels:  graphql, subscriptions
Aws Lambda Graphql
Use AWS Lambda + AWS API Gateway v2 for GraphQL subscriptions over WebSocket and AWS API Gateway v1 for HTTP
Stars: ✭ 313 (-95.45%)
Mutual labels:  graphql, subscriptions
Aws Mobile Appsync Sdk Ios
iOS SDK for AWS AppSync.
Stars: ✭ 231 (-96.64%)
Mutual labels:  graphql, codegen
Gatsby Typescript
Alternative typescript support plugin for Gatsbyjs. Aims to make using typescript in Gatsby as painless as possible
Stars: ✭ 95 (-98.62%)
Mutual labels:  graphql, codegen
Graphql Ws
Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client.
Stars: ✭ 398 (-94.22%)
Mutual labels:  graphql, subscriptions
Moviesapp
React Native Movies App: AWS Amplify, AWS AppSync, AWS Cognito, GraphQL, DynamoDB
Stars: ✭ 78 (-98.87%)
Mutual labels:  graphql, subscriptions
Nestjs Example
NestJS example with GraphQL, Schema-Stitching, Dataloader, GraphQL Upload, RabbitMQ, Redis, Scalable Websocket and JWT authentication
Stars: ✭ 111 (-98.39%)
Mutual labels:  graphql, dataloader
Type Graphql Dataloader
TypeGraphQL + DataLoader + TypeORM made easy
Stars: ✭ 73 (-98.94%)
Mutual labels:  graphql, dataloader
Dataloader Php
DataLoaderPhp is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.
Stars: ✭ 160 (-97.67%)
Mutual labels:  graphql, dataloader
Magiql
🌐 💫 Simple and powerful GraphQL Client, love child of react-query ❤️ relay
Stars: ✭ 45 (-99.35%)
Mutual labels:  graphql, codegen
Typeorm Graphql Loader
A query builder to easily resolve nested fields and relations for TypeORM-based GraphQL servers
Stars: ✭ 47 (-99.32%)
Mutual labels:  graphql, dataloader
Mercure
Server-sent live updates: protocol and reference implementation
Stars: ✭ 2,608 (-62.09%)
Mutual labels:  graphql, subscriptions
Java Dataloader
A Java 8 port of Facebook DataLoader
Stars: ✭ 367 (-94.67%)
Mutual labels:  graphql, dataloader

gqlgen

gqlgen Integration Coverage Status Go Report Card Go Reference Read the Docs

What is gqlgen?

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

  • gqlgen is based on a Schema first approach — You get to Define your API using the GraphQL Schema Definition Language.
  • 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

Quick start

  1. Initialise a new go module

    mkdir example
    cd example
    go mod init example
    
  2. Add github.com/99designs/gqlgen to your project's tools.go

    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
    

More help to get started:

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

We welcome contributions, Read our Contribution Guidelines to learn more about contributing to 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 it should only fetch friends if the user requested it. There are two ways to do this;

  • Using Custom Models

Write a custom model that omits the friends field:

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
  • Using Explicit Resolvers

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

# 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
}

You can also use inline config with directives to achieve the same result

directive @goModel(model: String, models: [String!]) on OBJECT
    | INPUT_OBJECT
    | SCALAR
    | ENUM
    | INTERFACE
    | UNION

directive @goField(forceResolver: Boolean, name: String) on INPUT_FIELD_DEFINITION
    | FIELD_DEFINITION

type User @goModel(model: "github.com/you/pkg/model.User") {
    id: ID!         @goField(name: "todoId")
    friends: [User!]!   @goField(forceResolver: true)
}

Can I change the type of the ID from type String to Type Int?

Yes! You can by remapping it in config as seen below:

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 isn't any way around this, gqlgen has no way to know what you want in a given context.

Other Resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].