github.com/dgraph-io/dgraph@v1.2.8/graphql/e2e/schema_subscribe/schema_subscribe_test.go (about)

     1  /*
     2   * Copyright 2020 Dgraph Labs, Inc. and Contributors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package schema_subscribe
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/dgraph-io/dgraph/graphql/e2e/common"
    23  	"github.com/dgraph-io/dgraph/testutil"
    24  	"github.com/stretchr/testify/require"
    25  )
    26  
    27  // This test is supposed to test the graphql schema subscribe feature. Whenever schema is updated
    28  // in a dgraph alpha for one group, that update should also be propogated to alpha nodes in other
    29  // groups.
    30  func TestSchemaSubscribe(t *testing.T) {
    31  	t.Skip()
    32  	groupOneServer := "http://localhost:8180/graphql"
    33  	groupOneAdminServer := "http://localhost:8180/admin"
    34  	groupTwoServer := "http://localhost:8182/graphql"
    35  	// groupTwoAdminServer := "http://localhost:8182/admin"
    36  	groupThreeServer := "http://localhost:8183/graphql"
    37  	groupThreeAdminServer := "http://localhost:8183/admin"
    38  
    39  	schema := `
    40  	type Author {
    41  		id: ID!
    42  		name: String!
    43  	}`
    44  	add := &common.GraphQLParams{
    45  		Query: `mutation updateGQLSchema($sch: String!) {
    46  			updateGQLSchema(input: { set: { schema: $sch }}) {
    47  				gqlSchema {
    48  					schema
    49  				}
    50  			}
    51  		}`,
    52  		Variables: map[string]interface{}{"sch": schema},
    53  	}
    54  	addResult := add.ExecuteAsPost(t, groupOneAdminServer)
    55  	require.Nil(t, addResult.Errors)
    56  
    57  	introspectionQuery := `
    58  	query {
    59  		__type(name: "Author") {
    60  			name
    61  			fields {
    62  				name
    63  			}
    64  		}
    65  	}`
    66  	introspect := &common.GraphQLParams{
    67  		Query: introspectionQuery,
    68  	}
    69  
    70  	expectedResult := `{"__type":{"name":"Author","fields":[{"name":"id"},{"name":"name"}]}}`
    71  	introspectionResult := introspect.ExecuteAsPost(t, groupOneServer)
    72  	require.Nil(t, introspectionResult.Errors)
    73  	testutil.CompareJSON(t, expectedResult, string(introspectionResult.Data))
    74  
    75  	introspectionResult = introspect.ExecuteAsPost(t, groupTwoServer)
    76  	require.Nil(t, introspectionResult.Errors)
    77  	testutil.CompareJSON(t, expectedResult, string(introspectionResult.Data))
    78  
    79  	introspectionResult = introspect.ExecuteAsPost(t, groupThreeServer)
    80  	require.Nil(t, introspectionResult.Errors)
    81  	testutil.CompareJSON(t, expectedResult, string(introspectionResult.Data))
    82  
    83  	// Now update schema on an alpha node for group 3 and see nodes in group 1 and 2 also get it.
    84  	schema = `
    85  	type Author {
    86  		id: ID!
    87  		name: String!
    88  		posts: [Post]
    89  	}
    90  
    91  	interface Post {
    92  		id: ID!
    93  	}`
    94  	add.Variables["sch"] = schema
    95  	addResult = add.ExecuteAsPost(t, groupThreeAdminServer)
    96  	require.Nil(t, addResult.Errors)
    97  
    98  	expectedResult = `{"__type":{"name":"Author","fields":[{"name":"id"},{"name":"name"},{"name":"posts"}]}}`
    99  	introspectionResult = introspect.ExecuteAsPost(t, groupOneServer)
   100  	require.Nil(t, introspectionResult.Errors)
   101  	testutil.CompareJSON(t, expectedResult, string(introspectionResult.Data))
   102  
   103  	introspectionResult = introspect.ExecuteAsPost(t, groupTwoServer)
   104  	require.Nil(t, introspectionResult.Errors)
   105  	testutil.CompareJSON(t, expectedResult, string(introspectionResult.Data))
   106  
   107  	introspectionResult = introspect.ExecuteAsPost(t, groupThreeServer)
   108  	require.Nil(t, introspectionResult.Errors)
   109  	testutil.CompareJSON(t, expectedResult, string(introspectionResult.Data))
   110  }