graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

Federated schema extended queries doesn't appear in gateway

Open pilucdes opened this issue 5 years ago • 2 comments

Describe the bug I have 3 services AccountingSVC , TenantSVC and a GatewaySVC. I currently use the federated pattern and trying to extend one of my model Transaction to aggregate a tenant to it. (A transaction is linked with one tenant). For some reasons the extended queries doesn't appear in my GatewaySVC. However, i'm able to call all other queries without problem. I tried to query the _schemaDefinition in my accounting downstream service and the result was the following :

{
  "data": {
    "_schemaDefinition": {
      "name": "accounting",
      "document": "schema { query: Query } type Query { _schemaDefinition(configuration: String!): _SchemaDefinition transactions: [Transaction] transaction(id: Int!): Transaction } type Transaction { id: ID! name: String tenantId: ID! } type _SchemaDefinition { name: String! document: String! extensionDocuments: [String!]! } \"The `@defer` directive may be provided for fragment spreads and inline fragments to inform the executor to delay the execution of the current fragment to indicate deprioritization of the current fragment. A query with `@defer` directive will cause the request to potentially return multiple responses, where non-deferred data is delivered in the initial response and data deferred is delivered in a subsequent response. `@include` and `@skip` take precedence over `@defer`.\" directive @defer(\"If this argument label has a value other than null, it will be passed on to the result of this defer directive. This label is intended to give client applications a way to identify to which fragment a deferred result belongs to.\" label: String \"Deferred when true.\" if: Boolean) on FRAGMENT_SPREAD | INLINE_FRAGMENT \"The @deprecated directive is used within the type system definition language to indicate deprecated portions of a GraphQL service's schema,such as deprecated fields on a type or deprecated enum values.\" directive @deprecated(\"Deprecations include a reason for why it is deprecated, which is formatted using Markdown syntax (as specified by CommonMark).\" reason: String = \"No longer supported\") on FIELD_DEFINITION | ENUM_VALUE \"Directs the executor to include this field or fragment only when the `if` argument is true.\" directive @include(\"Included when true.\" if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT \"Directs the executor to skip this field or fragment when the `if` argument is true.\" directive @skip(\"Skipped when true.\" if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT \"The `@stream` directive may be provided for a field of `List` type so that the backend can leverage technology such as asynchronous iterators to provide a partial list in the initial response, and additional list items in subsequent responses. `@include` and `@skip` take precedence over `@stream`.\" directive @stream(\"If this argument label has a value other than null, it will be passed on to the result of this stream directive. This label is intended to give client applications a way to identify to which fragment a streamed result belongs to.\" label: String \"The initial elements that shall be send down to the consumer.\" initialCount: Int! \"Streamed when true.\" if: Boolean!) on FIELD",
      "extensionDocuments": [
        "extend type Query { first: Transaction @delegate(schema: \"accounting\", path: \"transaction(id: 1)\") }"
      ]
    }
  }
}

To Reproduce Steps to reproduce the behavior:

  1. Download GraphQL Sandbox.zip
  2. Extract GraphQL Sandbox file in a project folder
  3. Run each services (you may use the scaffold if on windows)

Expected behavior Should be able to see all extended queries and the aggregation should also work

Desktop

  • OS: Windows 10
  • Version 10.0.19041 Build 19041

pilucdes avatar Dec 08 '20 16:12 pilucdes

There are multiple issues with your setup.

  1. The endpoints are swapped
services.AddHttpClient("tenants", (sp, client) =>
{
    client.BaseAddress = new Uri("http://localhost:5000/graphql");
});
services.AddHttpClient("accounting", (sp, client) =>
{
    client.BaseAddress = new Uri("http://localhost:5002/graphql");
});

tenants is actually 5002 and accounting is 5000.

Also, you need to provide the query type in your setup.

services
    .AddGraphQLServer()
    .ModifyRequestOptions(opt => opt.IncludeExceptionDetails = true)
    .AddQueryType(d => d.Name("Query"))
    .AddRemoteSchema("accounting")
    .AddRemoteSchema("tenants");

After fixing these your gateway works.

michaelstaib avatar Dec 09 '20 10:12 michaelstaib

This issue's conversation has been locked. Please file a new issue if you would like to continue the discussion.

ghost avatar Dec 09 '20 10:12 ghost