MCPcopy
hub / github.com/dgraph-io/dgraph / TestGraphQLQueryInCustomHTTPConfig

Function TestGraphQLQueryInCustomHTTPConfig

graphql/schema/wrappers_test.go:899–978  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

897}
898
899func TestGraphQLQueryInCustomHTTPConfig(t *testing.T) {
900 b, err := os.ReadFile("custom_http_config_test.yaml")
901 require.NoError(t, err, "Unable to read test file")
902
903 var tests []CustomHTTPConfigCase
904 err = yaml.Unmarshal(b, &tests)
905 require.NoError(t, err, "Unable to unmarshal tests to yaml.")
906
907 for _, tcase := range tests {
908 t.Run(tcase.Name, func(t *testing.T) {
909 schHandler, errs := NewHandler(tcase.GQLSchema, false)
910 require.NoError(t, errs)
911 sch, err := FromString(schHandler.GQLSchema(), x.RootNamespace)
912 require.NoError(t, err)
913
914 var vars map[string]interface{}
915 if tcase.GQLVariables != "" {
916 require.NoError(t, json.Unmarshal([]byte(tcase.GQLVariables), &vars))
917 }
918
919 op, err := sch.Operation(
920 &Request{
921 Query: tcase.GQLQuery,
922 Variables: vars,
923 })
924 require.NoError(t, err)
925 require.NotNil(t, op)
926
927 var field Field
928 if tcase.Type == "query" {
929 queries := op.Queries()
930 require.Len(t, queries, 1)
931 field = queries[0]
932 } else if tcase.Type == "mutation" {
933 mutations := op.Mutations()
934 require.Len(t, mutations, 1)
935 field = mutations[0]
936 } else if tcase.Type == "field" {
937 queries := op.Queries()
938 require.Len(t, queries, 1)
939 q := queries[0]
940 require.Len(t, q.SelectionSet(), 1)
941 // We are allow checking the custom http config on the first field of the query.
942 field = q.SelectionSet()[0]
943 }
944
945 c, err := field.CustomHTTPConfig()
946 require.NoError(t, err)
947
948 remoteSchemaHandler, errs := NewHandler(tcase.RemoteSchema, false)
949 require.NoError(t, errs)
950 remoteSchema, err := FromString(remoteSchemaHandler.GQLSchema(), x.RootNamespace)
951 require.NoError(t, err)
952
953 // Validate the generated query against the remote schema.
954 tmpl, ok := (c.Template).(map[string]interface{})
955 require.True(t, ok)
956

Callers

nothing calls this directly

Calls 10

GQLSchemaMethod · 0.95
CustomHTTPConfigMethod · 0.95
NewHandlerFunction · 0.85
FromStringFunction · 0.70
OperationMethod · 0.65
QueriesMethod · 0.65
LenMethod · 0.65
MutationsMethod · 0.65
SelectionSetMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected