graphql

package module
v0.0.0-...-7ebff8f Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0, BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Example
package main

import (
	"log"
	"net/http"

	"github.com/graphql-go/graphql"
	"github.com/graphql-go/handler"

	ddgraphql "github.com/DataDog/dd-trace-go/v2/contrib/graphql-go/graphql"
)

func main() {
	schema, err := ddgraphql.NewSchema(graphql.SchemaConfig{
		Query: graphql.NewObject(graphql.ObjectConfig{
			Name: "Query",
			Fields: graphql.Fields{
				"hello": &graphql.Field{
					Name: "hello",
					Type: graphql.NewNonNull(graphql.String),
				},
			},
		}),
	})
	if err != nil {
		panic(err)
	}

	http.Handle("/query", handler.New(&handler.Config{Schema: &schema}))
	log.Fatal(http.ListenAndServe(":8080", nil))

	// then:
	// $ curl -XPOST -d '{"query": "{ hello }"}' localhost:8080/query
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSchema

func NewSchema(config graphql.SchemaConfig, options ...Option) (graphql.Schema, error)

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option describes options for the GraphQL integration.

type OptionFn

type OptionFn func(*config)

OptionFn represents options applicable to NewSchema.

func WithAnalytics

func WithAnalytics(on bool) OptionFn

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate

func WithAnalyticsRate(rate float64) OptionFn

WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.

func WithService

func WithService(name string) OptionFn

WithService sets the given service name for the client.

Jump to

Keyboard shortcuts

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