graphql

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: Apache-2.0, BSD-3-Clause Imports: 13 Imported by: 1

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/contrib/graphql-go/graphql/v2"
	"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
)

func main() {
	tracer.Start()
	defer tracer.Stop()

	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
}

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 WithErrorExtensions

func WithErrorExtensions(errExtensions ...string) OptionFn

WithErrorExtensions allows to configure the error extensions to include in the error span events.

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