Skip to content

iamgoangle/go-graphql-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-graphql-tutorial

Just an example for Graph Query language.

GQL Stacks

  • gqlgen
  • gin

Federation?

  • The idea is distributed graphs
  • Building a new unified and single Graph API (by combining multiple graph schemas)
  • With GraphQL federation, you tell the gateway where it needs to look for the different objects and what URLs they live at. The subgraphs provide metadata that the gateway uses to automatically stitch everything together. This is a low-maintenance approach that gives your team a lot of flexibility.
  • Have a gateway layer
  • Split or decentralized yet interoperable among teams working in different locations
  • Schemas are split across multiple services, and as they grow or scale over time, federation via the “gateway” layer

Develop Guides

References

Getting Started

cmd/gql

GraphQL

  1. setup module
go mod init <your_module>
  1. Initialise gqlgen config and generate models
go run github.com/99designs/gqlgen init

The project skeleton will be created. you can read more about skeleton structure and file from [here](go run github.com/99designs/gqlgen init)

  1. Removed unnecessary code from generated file. Here you are going to leave gqlgen.yml on your project.
├── gqlgen.yml               - The gqlgen config file, knobs for controlling the generated code.
  1. Modify the schema which are includes schema, mutation and query.
  2. Run go run github.com/99designs/gqlgen generate to re-generate the schema
  3. Make sure all schema has been updated by git diff

cmd/gql-server

GraphlQL Server and Playground

go run main.go

Playground Queries

Mutation

mutation createTodo {
  createTodo(input: { text: "golf todo", userId: "1" }) {
    user {
      id
    }
    text
    done
  }
}

Query

query findTodos {
  todos {
    user {
      id
      name
    }
    text
  }
}

Releases

No releases published

Packages

No packages published

Languages