Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: entity exists as a field for more than entity #3

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 4 additions & 2 deletions src/core/blueprint/operators/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ fn create_related_fields(
if visited.contains(type_name) {
return RelatedFields(map);
}
visited.insert(type_name.to_string());

if let Some(type_) = config.find_type(type_name) {
for (name, field) in &type_.fields {
Expand All @@ -34,6 +33,8 @@ fn create_related_fields(
create_related_fields(config, field.type_of.name(), visited),
),
);

visited.insert(type_name.to_string());
}
} else {
map.insert(
Expand All @@ -43,6 +44,7 @@ fn create_related_fields(
create_related_fields(config, field.type_of.name(), visited),
),
);
visited.insert(type_name.to_string());
}
}
}
Expand All @@ -51,7 +53,7 @@ fn create_related_fields(
map.extend(create_related_fields(config, type_name, visited).0);
}
};

visited.insert(type_name.to_string());
RelatedFields(map)
}

Expand Down
21 changes: 21 additions & 0 deletions tests/core/snapshots/graphql-conformance-019.md_0.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
source: tests/core/spec.rs
expression: response
---
{
"status": 200,
"headers": {
"content-type": "application/json"
},
"body": {
"data": {
"user": {
"newName": "Tailcall",
"userPost": {
"id": 0,
"content": "Hello from user 4"
}
}
}
}
}
21 changes: 21 additions & 0 deletions tests/core/snapshots/graphql-conformance-019.md_1.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
source: tests/core/spec.rs
expression: response
---
{
"status": 200,
"headers": {
"content-type": "application/json"
},
"body": {
"data": {
"page": {
"name": "Tailcall_page",
"pagePost": {
"id": 1,
"content": "Hello from page 4"
}
}
}
}
}
29 changes: 29 additions & 0 deletions tests/core/snapshots/graphql-conformance-019.md_client.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
source: tests/core/spec.rs
expression: formatted
---
type Page {
id: ID!
name: String!
pagePost: Post
}

type Post {
content: String
id: ID!
}

type Query {
page(id: ID!): Page!
user(id: ID!): User!
}

type User {
id: ID!
newName: String!
userPost: Post
}

schema {
query: Query
}
31 changes: 31 additions & 0 deletions tests/core/snapshots/graphql-conformance-019.md_merged.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
source: tests/core/spec.rs
expression: formatter
---
schema @server(hostname: "0.0.0.0", port: 8001, queryValidation: false) @upstream(httpCache: 42) {
query: Query
}

type Page {
id: ID!
name: String!
post: Post @modify(name: "pagePost")
}

type Post {
content: String
id: ID!
}

type Query {
page(id: ID!): Page!
@graphQL(args: [{key: "id", value: "{{.args.id}}"}], url: "http://upstream/graphql", name: "page")
user(id: ID!): User!
@graphQL(args: [{key: "id", value: "{{.args.id}}"}], url: "http://upstream/graphql", name: "user")
}

type User {
id: ID!
name: String! @modify(name: "newName")
post: Post @modify(name: "userPost")
}
91 changes: 91 additions & 0 deletions tests/execution/graphql-conformance-019.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Composed queries with field modify check

```graphql @config
schema @server(port: 8001, queryValidation: false, hostname: "0.0.0.0") @upstream(httpCache: 42) {
query: Query
}

type Query {
user(id: ID!): User!
@graphQL(url: "http://upstream/graphql", name: "user", args: [{key: "id", value: "{{.args.id}}"}])
page(id: ID!): Page!
@graphQL(url: "http://upstream/graphql", name: "page", args: [{key: "id", value: "{{.args.id}}"}])
}

type User {
id: ID!
name: String! @modify(name: "newName")
post: Post @modify(name: "userPost")
}

type Page {
id: ID!
name: String!
post: Post @modify(name: "pagePost")
}

type Post {
id: ID!
content: String
}
```

```yml @mock
- request:
method: POST
url: http://upstream/graphql
textBody: '{ "query": "query { user(id: 4) { name post { id content } } }" }'
expectedHits: 1
response:
status: 200
body:
data:
user:
name: Tailcall
post:
id: 0
content: Hello from user 4
- request:
method: POST
url: http://upstream/graphql
textBody: '{ "query": "query { page(id: 4) { name post { id content } } }" }'
expectedHits: 1
response:
status: 200
body:
data:
page:
name: Tailcall_page
post:
id: 1
content: Hello from page 4
```

```yml @test
- method: POST
url: http://localhost:8080/graphql
body:
query: |
query getUser {
user(id: 4) {
newName
userPost {
id
content
}
}
}
- method: POST
url: http://localhost:8080/graphql
body:
query: |
query getPage {
page(id: 4) {
name
pagePost {
id
content
}
}
}
```
Loading