...

Source file src/github.com/99designs/gqlgen/codegen/testserver/followschema/mutation_with_custom_scalar_test.go

Documentation: github.com/99designs/gqlgen/codegen/testserver/followschema

     1  package followschema
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/99designs/gqlgen/client"
    10  	"github.com/99designs/gqlgen/graphql/handler"
    11  )
    12  
    13  func TestErrorInsideMutationArgument(t *testing.T) {
    14  	resolvers := &Stub{}
    15  	resolvers.MutationResolver.UpdateSomething = func(_ context.Context, input SpecialInput) (s string, err error) {
    16  		return "Hello world", nil
    17  	}
    18  
    19  	c := client.New(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: resolvers})))
    20  
    21  	t.Run("mutation with correct input doesn't return error", func(t *testing.T) {
    22  		var resp map[string]interface{}
    23  		input := map[string]interface{}{
    24  			"nesting": map[string]interface{}{
    25  				"field": "email@example.com",
    26  			},
    27  		}
    28  		err := c.Post(
    29  			`mutation TestMutation($input: SpecialInput!) { updateSomething(input: $input) }`,
    30  			&resp,
    31  			client.Var("input", input),
    32  		)
    33  		require.Equal(t, resp["updateSomething"], "Hello world")
    34  		require.NoError(t, err)
    35  	})
    36  
    37  	t.Run("mutation with incorrect input returns full path", func(t *testing.T) {
    38  		var resp map[string]interface{}
    39  		input := map[string]interface{}{
    40  			"nesting": map[string]interface{}{
    41  				"field": "not-an-email",
    42  			},
    43  		}
    44  		err := c.Post(
    45  			`mutation TestMutation($input: SpecialInput!) { updateSomething(input: $input) }`,
    46  			&resp,
    47  			client.Var("input", input),
    48  		)
    49  		require.EqualError(t, err, `[{"message":"invalid email format","path":["updateSomething","input","nesting","field"]}]`)
    50  	})
    51  }
    52  

View as plain text