Discover Packages
github.com/sebastianrath/graphql-reflect-go
command
module
Version:
v0.0.0-...-6a0bf9a
Opens a new window with list of versions in this module.
Published: Dec 27, 2023
License: MIT
Opens a new window with license information.
Imports: 9
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
GraphQL query API for Go structs
Overview
This API provides a simple and efficient way to query specific fields from Go structs.
Key Features
Selective Field Queries : Query only the fields you need.
Nested Struct Support : Ability to query fields within nested structs.
Easy Integration : Works seamlessly with popular Go frameworks like Echo, also check out the examples.
Quick Start
Define Your Structs :
Example:
type Cat struct {
Name string `json:"name"`
Age int `json:"age"`
Color string `json:"color"`
}
Use QueryStructViaGraphql
Function :
This function helps in querying a struct based on the provided GraphQL query string.
Example:
func QueryCats(c echo.Context) error {
...
b, err := QueryStructViaGraphql("cats", cats, post.Query);
...
}
Set Up Routes :
Use your favorite framework (like Echo) to set up routes and handle requests.
Example:
e.POST("/dogs", QueryDogs)
e.POST("/cats", QueryCats)
Run Your Server :
e.Logger.Fatal(e.Start(":8000"))
Usage
Make a POST request to /cats
or /dogs
with a request body containing your GraphQL query.
Example Request Body:
{
cats
{
name
age
}
}
Response will contain only the name
and age
fields for the respective struct. A Postman example file called postman_examples_import_me.json
is included in the repository. Start the Go server via go run .
and import the json file into Postman to try out the examples.
License
MIT License. See LICENSE for more information.
Expand ▾
Collapse ▴
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.