Just an example for Graph Query language.
- gqlgen
- gin
- 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
- Learning about schema https://graphql.org/learn/schema/
- https://gqlgen.com/getting-started/
- https://gqlgen.com/recipes/federation/
References
- https://blog.logrocket.com/the-what-when-why-and-how-of-federated-graphql/
- https://www.apollographql.com/docs/federation/
GraphQL
- setup module
go mod init <your_module>- Initialise gqlgen config and generate models
go run github.com/99designs/gqlgen initThe project skeleton will be created. you can read more about skeleton structure and file from [here](go run github.com/99designs/gqlgen init)
- Removed unnecessary code from generated file. Here you are going to leave
gqlgen.ymlon your project.
├── gqlgen.yml - The gqlgen config file, knobs for controlling the generated code.- Modify the
schemawhich are includes schema, mutation and query. - Run
go run github.com/99designs/gqlgen generateto re-generate the schema - Make sure all schema has been updated by
git diff
GraphlQL Server and Playground
go run main.goMutation
mutation createTodo {
createTodo(input: { text: "golf todo", userId: "1" }) {
user {
id
}
text
done
}
}Query
query findTodos {
todos {
user {
id
name
}
text
}
}