Conversation
rebello95
left a comment
There was a problem hiding this comment.
Left some comments documenting our discussion earlier today, as well as a few other things I noticed 😄 Thanks for the hard work here!
| used on operation roots. | ||
|
|
||
| If `@mock` is applied to non-root fields only, the client must transform the | ||
| document to remove any selections which have `@mock` applied before sending the |
There was a problem hiding this comment.
One thing that is probably worth noting here is that for a document to remain valid, the field removal likely needs to happen recursively:
- Empty selection sets are invalid, so if all fields within a selection set are marked with
@mock, the parent field needs to be removed as well. Same goes for fragment definitions and inline fragments - Unused variables are invalid, so if a
@mocked field is the only field that used an argument, the argument needs to be removed from the root query - An operation with no selection sets is invalid,
@mocking all top-level fields should be disallowed (in favor of mocking the top-level operation itself)
There was a problem hiding this comment.
Looks like these clarifications are still missing; maybe we add them to the next line?
| #### __appliesTo__ | ||
|
|
||
| {"__appliesTo__"} must be defined as the resolved | ||
| _[schema coordinate](https://spec.graphql.org/September2025/#sec-Schema-Coordinates)_ | ||
| of the field or root operation type where `@mock` is applied, or may be applied, | ||
| with the *mock variant id*. | ||
|
|
||
| **Example** | ||
|
|
||
| For the following fragment: | ||
|
|
||
| ```graphql example | ||
| fragment FooFields on Foo { | ||
| # location resolves to "Foo.bar" | ||
| bar @mock(variant: "basic-bar") | ||
|
|
||
| # location resolves to "Foo.baz" | ||
| baz @mock(variant: "basic-baz") { | ||
| qux | ||
| } | ||
| } | ||
| ``` |
There was a problem hiding this comment.
From our call today:
- Using schema coordinates here will not work for field aliases (since those don't exist in the schema)
- We need to know the path for which a given mock is being applied to (not only the type) in order to ensure it provides necessary data for all the required fields (see the example below -
user-1anduser-2variants represent the same type, but both would be invalid for the other's field path) - To work around this, we propose changing
__appliesTo__to__path__and changing its representation to be a path relative to the parent executable fragment/operation - For
@mockon the root query,__path__could be.<root>, or something else
query SomeQuery {
user(id: 123) @mock(variant: 'user-1') { # returns User
name
}
house(id: 123) { # returns User
owner @mock(variant: 'renter-1') {
name
avatarUrl
}
}
somethingElseThatReturnsAUser @mock(variant: 'user-2') { # returns User
password
}
}There was a problem hiding this comment.
Option 1
@mockon a query root does__path__ = "Query"@mockwithin queries do__path__ = "Query.bar.baz"@mockwithin fragments do__path__ = "Foo.bar.baz"(where "Foo" is the name of the fragment)
this feels nice but also possibly redundant, given that the "Query." or "." prefix is already implied by the mock file name.
Option 2
Same as above but remove the "Query." prefix for mocks within an operation/fragment:
@mockon a query root does__path__ = "Query"@mockwithin queries do__path__ = "bar.baz"@mockwithin fragments do__path__ = "bar.baz"
Given that response positions also do not use a "Query." prefix I guess I'll go with option 2, but happy to bikeshed on this.
There was a problem hiding this comment.
@benjie points out that https://github.com/graphql/graphql-wg/blob/main/rfcs/OperationExpressions.md is already a (proposed) thing we could use here instead.
|
|
||
| #### data | ||
|
|
||
| :: {"data"} stores the *mock value*. It may be `null` if the field is nullable. |
There was a problem hiding this comment.
It might be worth noting that this data will be automatically inserted within the root data key in the operation's response data. In other words, for a @mock on a root query, its entry would be this:
{
"mock-id": {
"data": {
"business": {
"name": "The Great British Bakery",
"rating": 5.0
}
},
...
},
}not this:
{
"mock-id": {
"data": {
"data" {
"business": {
"name": "The Great British Bakery",
"rating": 5.0
}
}
},
...
},
}
rebello95
left a comment
There was a problem hiding this comment.
Great work on this! I read through the whole thing and mostly have small nits/comments. Overall this is coming together!
| used on operation roots. | ||
|
|
||
| If `@mock` is applied to non-root fields only, the client must transform the | ||
| document to remove any selections which have `@mock` applied before sending the |
There was a problem hiding this comment.
Looks like these clarifications are still missing; maybe we add them to the next line?
|
|
||
| The values generated for leaf nodes do not matter and do not need to be | ||
| preserved or included in the description - unless otherwise specified by the | ||
| user. |
There was a problem hiding this comment.
Would suggest mentioning that aliases should be used in __path__ when present
| 3. If creating a new mock, create a new entry with a descriptive mock variant id | ||
| 4. Ensure the mock value includes appropriate `data` and/or `errors` fields | ||
| 5. Add a summary of the user's prompt to the `__description__` field | ||
| 6. Write the updated mock file |
There was a problem hiding this comment.
| 6. Write the updated mock file | |
| 6. Write the updated mock file (do not modify other mocks in the file) |
|
|
||
| ## Schema | ||
|
|
||
| Look for the GraphQL schema in <repo_root>/schema.graphql to understand what |
There was a problem hiding this comment.
| Look for the GraphQL schema in <repo_root>/schema.graphql to understand what | |
| Look for the GraphQL schema in <repo_root>/schema.graphqls to understand what |
May want to consider removing the filename here since it's implementation-specific
Co-authored-by: Michael Rebello <me@michaelrebello.com>
Co-authored-by: Michael Rebello <me@michaelrebello.com>
Co-authored-by: Michael Rebello <me@michaelrebello.com>
Co-authored-by: Michael Rebello <me@michaelrebello.com>
Co-authored-by: Michael Rebello <me@michaelrebello.com>
Co-authored-by: Michael Rebello <me@michaelrebello.com>
Co-authored-by: Michael Rebello <me@michaelrebello.com>
Co-authored-by: Michael Rebello <me@michaelrebello.com>
Co-authored-by: Michael Rebello <me@michaelrebello.com>
see graphql/ai-wg#79
Prior art! https://medium.com/airbnb-engineering/graphql-data-mocking-at-scale-with-llms-and-generatemock-30b380f12bd6