graphql-engine
graphql-engine copied to clipboard
Can't return Interface type when using Remote schema Permissions
Version Information
Server Version: 2.8.3 CLI Version (for CLI related issue): v2.4.0
Environment
What is the current behaviour?
I have a remote schema with a field that resolves to an interface type, where there are some shared fields (such as id, name, and type), and then child fields that inherit from that field. It's much cleaner to do this than to implement unions since most of the child fields have only slightly different fields.
I'm able to query this in the console (when using the admin role). In the example below schema is a field of interface type IWorkspacePropertySchema
But when trying to add remote schema permissions for my resolver, it throws an error saying that it couldn't find the interface type:
{ "path": "$.args[0].args", "error": "Could not find type with name \"IWorkspacePropertySchema\"", "code": "remote-schema-error" }
What is the expected behaviour?
How to reproduce the issue?
1.create a resolver with an object type containing a field that is an interface 2. query for that resolver in the graphql console 3. create remote schema permissions for that resolver using any other role.
This seems to be a console issue where it doesn't pass the schema correctly to the backend when adding permissions with GraphQL interfaces. However, the good news is that you will be able to get it working by directly applying the changes to the metadata. Take a look at the example below.
If I have a remote schema with the following GraphQL schema -
interface Item {
price: Int
name: String
}
type Book implements Item {
title: String
author: String
price: Int
name: String
}
type Query {
books: [Book]
items: [Item]
}
If I want to allow a role user
to query the field items
and books
, I can do it by applying the following metadata -
- name: books-schema
definition:
url_from_env: REMOTE_SCHEMA_ENDPOINT
timeout_seconds: 60
comment: ""
permissions:
- role: user
definition:
schema: |
type Book implements Item {
author: String
name: String
price: Int
title: String
}
interface Item {
price: Int
name: String
}
type Query {
books: [Book]
items: [Item]
}
Please don't forget to add the implements
syntax to all the types that implement the interface or else the query will not work.