Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,95 @@ Same for the the Mutation type's field listing, `Blog`'s mutation fields appear,
}
```

**Mixed Field Queries**

If a query contains both an introspection field (`__schema`, `__type`) and a data
field, and introspection is disabled, only the introspection fields return an error, the data field is resolved correctly:

=== "Query"

```graphql
{
__schema { types { name } }
blogCollection { edges { node { id } } }
}
```

=== "Response"

```json
{
"data": {
"blogCollection": {
"edges": [
{
"node": {
"id": 1,
"content": "hello, world"
}
}
]
}
},
"errors": [
{
"message": "Unknown field \"__schema\" on type Query"
}
]
}
```

If there are two schemas with introspection enabled only on one schema, there is no error on the instrospection fields but entities from the introspection disabled schema are filtered out:

=== "Query"

```graphql
{
__schema { types { name } }
accountCollection { edges { node { id email } } }
blogCollection { edges { node { id content } } }
}
```

=== "Response"

```json
{
"data": {
"__schema": {
"queryType": {
"fields": [
{ "name": "blogCollection" },
{ "name": "node" }
// no accountCollection
]
}
},
"blogCollection": {
"edges": [
{
"node": {
"id": 1,
"content": "hello, world"
}
}
]
},
"accountCollection": {
"edges": [
{
"node": {
"id": 1,
"email": "alice@example.com"
}
}
]
}
},
// no errors
}
```

#### Non-introspection Queries

Non-introspection queries are not affected by disabling introspection. `accountCollection`, `insertIntoAccountCollection`, etc. continue to resolve normally as long as the role has the underlying SQL privileges:
Expand Down
11 changes: 8 additions & 3 deletions src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,15 @@ where
},
}
}
let any_field_succeeded = res_data
.as_object()
.map(|o| !o.is_empty())
.unwrap_or(false);
GraphQLResponse {
data: match res_errors.len() {
0 => Omit::Present(res_data),
_ => Omit::Present(serde_json::Value::Null),
data: if res_errors.is_empty() || any_field_succeeded {
Omit::Present(res_data)
} else {
Omit::Present(serde_json::Value::Null)
},
errors: match res_errors.len() {
0 => Omit::Omitted,
Expand Down
Loading