Shared types in GraphQL Federation (@shareable)

Hey @DavidS,

we are slowly getting to the bottom of this. :smile:

I think we have to distinguish between two schemas:

  1. The schemas mentioned above for “reviews” and “shows” is what is defined as input in textfile format in the service (shows schema, reviews schema)
  2. At runtime there is a federation specific, generated SDL that can be queried in the following way:
query sdl {
  _service {
    sdl
  }
}

This SDL should be the source for the federation gateway.

The Netflix DGS framework (or probably the underlying graphql-java library) generates an entry

schema {
  query: Query
}

into this SDL for every downstream service (even if this is not explicitly part of the “input” schema, see 1.).

The question would be: Is this behavior correct as specified? Would this be a point where Tyk would have to be a little more lenient and robust? Or is it a bug in the graphql-java library?

The Apollo Gateway by the way accepts these SDLs… :wink:

This is what the SDL string for “shows” looks like then, when queried as described:

schema {\n  query: Query\n}\n\ntype Query {\n  shows(titleFilter: String): [Show]\n}\n\ntype Show @key(fields : \"id\") {\n  id: ID\n  releaseYear: Int\n  title: String\n}\n\nenum ErrorDetail {\n  \"\"\"\n  The deadline expired before the operation could complete.\n  \n  For operations that change the state of the system, this error\n  may be returned even if the operation has completed successfully.\n  For example, a successful response from a server could have been\n  delayed long enough for the deadline to expire.\n  \n  HTTP Mapping: 504 Gateway Timeout\n  Error Type: UNAVAILABLE\n  \"\"\"\n  DEADLINE_EXCEEDED\n  \"\"\"\n  The server detected that the client is exhibiting a behavior that\n  might be generating excessive load.\n  \n  HTTP Mapping: 429 Too Many Requests or 420 Enhance Your Calm\n  Error Type: UNAVAILABLE\n  \"\"\"\n  ENHANCE_YOUR_CALM\n  \"\"\"\n  The requested field is not found in the schema.\n  \n  This differs from `NOT_FOUND` in that `NOT_FOUND` should be used when a\n  query is valid, but is unable to return a result (if, for example, a\n  specific video id doesn't exist). `FIELD_NOT_FOUND` is intended to be\n  returned by the server to signify that the requested field is not known to exist.\n  This may be returned in lieu of failing the entire query.\n  See also `PERMISSION_DENIED` for cases where the\n  requested field is invalid only for the given user or class of users.\n  \n  HTTP Mapping: 404 Not Found\n  Error Type: BAD_REQUEST\n  \"\"\"\n  FIELD_NOT_FOUND\n  \"\"\"\n  The client specified an invalid argument.\n  \n  Note that this differs from `FAILED_PRECONDITION`.\n  `INVALID_ARGUMENT` indicates arguments that are problematic\n  regardless of the state of the system (e.g., a malformed file name).\n  \n  HTTP Mapping: 400 Bad Request\n  Error Type: BAD_REQUEST\n  \"\"\"\n  INVALID_ARGUMENT\n  \"\"\"\n  The provided cursor is not valid.\n  \n  The most common usage for this error is when a client is paginating\n  through a list that uses stateful cursors. In that case, the provided\n  cursor may be expired.\n  \n  HTTP Mapping: 404 Not Found\n  Error Type: NOT_FOUND\n  \"\"\"\n  INVALID_CURSOR\n  \"\"\"\n  Unable to perform operation because a required resource is missing.\n  \n  Example: Client is attempting to refresh a list, but the specified\n  list is expired. This requires an action by the client to get a new list.\n  \n  If the user is simply trying GET a resource that is not found,\n  use the NOT_FOUND error type. FAILED_PRECONDITION.MISSING_RESOURCE\n  is to be used particularly when the user is performing an operation\n  that requires a particular resource to exist.\n  \n  HTTP Mapping: 400 Bad Request or 500 Internal Server Error\n  Error Type: FAILED_PRECONDITION\n  \"\"\"\n  MISSING_RESOURCE\n  \"\"\"\n  Service Error.\n  \n  There is a problem with an upstream service.\n  \n  This may be returned if a gateway receives an unknown error from a service\n  or if a service is unreachable.\n  If a request times out which waiting on a response from a service,\n  `DEADLINE_EXCEEDED` may be returned instead.\n  If a service returns a more specific error Type, the specific error Type may\n  be returned instead.\n  \n  HTTP Mapping: 502 Bad Gateway\n  Error Type: UNAVAILABLE\n  \"\"\"\n  SERVICE_ERROR\n  \"\"\"\n  Request failed due to network errors.\n  \n  HTTP Mapping: 503 Unavailable\n  Error Type: UNAVAILABLE\n  \"\"\"\n  TCP_FAILURE\n  \"\"\"\n  Request throttled based on server concurrency limits.\n  \n  HTTP Mapping: 503 Unavailable\n  Error Type: UNAVAILABLE\n  \"\"\"\n  THROTTLED_CONCURRENCY\n  \"\"\"\n  Request throttled based on server CPU limits\n  \n  HTTP Mapping: 503 Unavailable.\n  Error Type: UNAVAILABLE\n  \"\"\"\n  THROTTLED_CPU\n  \"\"\"\n  The operation is not implemented or is not currently supported/enabled.\n  \n  HTTP Mapping: 501 Not Implemented\n  Error Type: BAD_REQUEST\n  \"\"\"\n  UNIMPLEMENTED\n  \"\"\"\n  Unknown error.\n  \n  This error should only be returned when no other error detail applies.\n  If a client sees an unknown errorDetail, it will be interpreted as UNKNOWN.\n  \n  HTTP Mapping: 500 Internal Server Error\n  \"\"\"\n  UNKNOWN\n}\n\nenum ErrorType {\n  \"\"\"\n  Bad Request.\n  \n  There is a problem with the request.\n  Retrying the same request is not likely to succeed.\n  An example would be a query or argument that cannot be deserialized.\n  \n  HTTP Mapping: 400 Bad Request\n  \"\"\"\n  BAD_REQUEST\n  \"\"\"\n  The operation was rejected because the system is not in a state\n  required for the operation's execution.  For example, the directory\n  to be deleted is non-empty, an rmdir operation is applied to\n  a non-directory, etc.\n  \n  Service implementers can use the following guidelines to decide\n  between `FAILED_PRECONDITION` and `UNAVAILABLE`:\n  \n  - Use `UNAVAILABLE` if the client can retry just the failing call.\n  - Use `FAILED_PRECONDITION` if the client should not retry until\n  the system state has been explicitly fixed.  E.g., if an \"rmdir\"\n       fails because the directory is non-empty, `FAILED_PRECONDITION`\n  should be returned since the client should not retry unless\n  the files are deleted from the directory.\n  \n  HTTP Mapping: 400 Bad Request or 500 Internal Server Error\n  \"\"\"\n  FAILED_PRECONDITION\n  \"\"\"\n  Internal error.\n  \n  An unexpected internal error was encountered. This means that some\n  invariants expected by the underlying system have been broken.\n  This error code is reserved for serious errors.\n  \n  HTTP Mapping: 500 Internal Server Error\n  \"\"\"\n  INTERNAL\n  \"\"\"\n  The requested entity was not found.\n  \n  This could apply to a resource that has never existed (e.g. bad resource id),\n  or a resource that no longer exists (e.g. cache expired.)\n  \n  Note to server developers: if a request is denied for an entire class\n  of users, such as gradual feature rollout or undocumented allowlist,\n  `NOT_FOUND` may be used. If a request is denied for some users within\n  a class of users, such as user-based access control, `PERMISSION_DENIED`\n  must be used.\n  \n  HTTP Mapping: 404 Not Found\n  \"\"\"\n  NOT_FOUND\n  \"\"\"\n  The caller does not have permission to execute the specified\n  operation.\n  \n  `PERMISSION_DENIED` must not be used for rejections\n  caused by exhausting some resource or quota.\n  `PERMISSION_DENIED` must not be used if the caller\n  cannot be identified (use `UNAUTHENTICATED`\n  instead for those errors).\n  \n  This error Type does not imply the\n  request is valid or the requested entity exists or satisfies\n  other pre-conditions.\n  \n  HTTP Mapping: 403 Forbidden\n  \"\"\"\n  PERMISSION_DENIED\n  \"\"\"\n  The request does not have valid authentication credentials.\n  \n  This is intended to be returned only for routes that require\n  authentication.\n  \n  HTTP Mapping: 401 Unauthorized\n  \"\"\"\n  UNAUTHENTICATED\n  \"\"\"\n  Currently Unavailable.\n  \n  The service is currently unavailable.  This is most likely a\n  transient condition, which can be corrected by retrying with\n  a backoff.\n  \n  HTTP Mapping: 503 Unavailable\n  \"\"\"\n  UNAVAILABLE\n  \"\"\"\n  Unknown error.\n  \n  For example, this error may be returned when\n  an error code received from another address space belongs to\n  an error space that is not known in this address space.  Also\n  errors raised by APIs that do not return enough error information\n  may be converted to this error.\n  \n  If a client sees an unknown errorType, it will be interpreted as UNKNOWN.\n  Unknown errors MUST NOT trigger any special behavior. These MAY be treated\n  by an implementation as being equivalent to INTERNAL.\n  \n  When possible, a more specific error should be provided.\n  \n  HTTP Mapping: 520 Unknown Error\n  \"\"\"\n  UNKNOWN\n}\n