Git Product home page Git Product logo

graphql-reflect-go's Introduction

GraphQL query API for Go structs

Overview

GraphQL Logo

This API provides a simple and efficient way to query specific fields from Go structs.

Key Features

  1. Selective Field Queries: Query only the fields you need.
  2. Nested Struct Support: Ability to query fields within nested structs.
  3. Easy Integration: Works seamlessly with popular Go frameworks like Echo, also check out the examples.

Quick Start

  1. Define Your Structs:

    Example:

    type Cat struct {
        Name string `json:"name"`
        Age  int    `json:"age"`
        Color string `json:"color"`
    }
  2. 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);
        ...
    }
  3. 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)
  4. 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.

graphql-reflect-go's People

Contributors

sebastianrath avatar dependabot[bot] 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.