graphql

package
v0.0.0-...-1579a05 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Operation

type Operation = ast.Operation

Operation represents a GraphQL operation. It can be one of Query, Mutation or Subscription.

const (
	Query        Operation = "query"
	Mutation     Operation = "mutation"
	Subscription Operation = "subscription"
)

type Request

type Request struct {
	Query         string                 `json:"query"`
	OperationName string                 `json:"operationName,omitempty"`
	Variables     map[string]interface{} `json:"variables,omitempty"`
}

Request represents a GraphQL request.

func ParseGraphQLRequest

func ParseGraphQLRequest(r *http.Request) (*Request, error)

ParseGraphQLRequest parses a GraphQL request from an http.Request. It supports GET and POST requests. If the request is a GET request, it expects the query parameter to be present. In case of POST request the Content-Type header must be application/json or application/graphql.

func (Request) Parse

func (r Request) Parse() (Operation, string, error)

ParseQuery parses a GraphQL request. Return the type of the operation. if OperationName is present in query it returns the same name as Request.OperationName if OperationName is not preset in query it returns an error if OperationName is not specified and there are multiple operations in query it retruns an error if OperationName is not specified and there is only one operation in query it returns the name of that operation if the query has multiple operations with same name it will return the first one

type Response

type Response struct {
	Data   map[string]interface{} `json:"data,omitempty"`
	Errors []interface{}          `json:"errors,omitempty"`
}

Response represents a GraphQL response.

Jump to

Keyboard shortcuts

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