client

command module
v0.0.0-...-838b099 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 5 Imported by: 0

README

GraphQL Client in Go

An example of implementing a simple GraphQL client in Go to query against a public GraphQL service https://countries.trevorblades.com/. The client makes 2 calls:

  • GraphQL request without any filter.
  • GraphQL request with a filter passed as a parameter.

We can construct a GraphQL query as a string and pass it as plain text when making the API call. But for the construction of more complex queries, including support for passed arguments, we may want to use a GraphQL package, like the machinebox/graphql package.

Setup

  1. Run the program

    $ make
    

Querying from the Playground

GraphQL is a querying language that can be embedded in a programming language like Go and a transport stack like HTTP. The following steps show how the same GraphQL queries can be made from the service GraphQL playground.

  1. Go to https://countries.trevorblades.com/

  2. Run the following query to return all countries.

    query {
      countries {
        code,
        name,
        languages {
          name
        }
      }
    }
    
  3. Return all countries that matches country.code == "US" (case sensitive).

    query {
      countries(filter: {
        code: { eq: "US" }
      }) {
        code,
        name,
        languages {
          name
        }
      }
    }
    

Reference

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL