-
Notifications
You must be signed in to change notification settings - Fork 53
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
Support multiple schemas #51
Conversation
I wasn't able to run the bucklescript tests without the same changes as #50 had. |
Thank you! It's a really good addition. What do you think about adjusting second param to support more fine-tuning like generating serialize function? #20 (comment) |
That sounds really good @baransu. So for this PR, instead of having this secondary argument as a string, having it as an object instead? Some thing like module MyQuery = [%graphql
{|
query pokemon($id: String, $name: String) {
pokemon(name: $name, id: $id) {
id
name
}
}
|};
{schema: "pokedex_schema.json"}
]; |
Exactly like this. I'm only afraid of how it would work with optional arguments when you want to specify only part of additional params. |
Having it as an object instead of record should solve that right? That way it doesn't really need to be a certain type/shape. The PPX can just look for different values of the object |
It means you can put in stuff that isn't doing anything, but at least we won't need to specify keys that we want default values to apply to? |
I'll experiment and ping you when I have an update. I think the suggestion above should just work as is 👍 |
@baransu I've changed it to be a record. This works for any object since the PPX runs before the type checker. To support other fields all you need to add is a separate function for the specific field you want similar to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR. Thank you @arnarthor. I only have few comments about code quality 🙂
|
||
test("Allows you to omit nullable arguments", () => | ||
expect(MyQuery.make(~name="Pikachu", ())##variables) | ||
== Js.Json.parseExn({| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change to |> based tests. I think it's more readable that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/native/graphql_ppx.re
Outdated
@@ -72,7 +72,7 @@ let drop_prefix = (prefix, str) => { | |||
String.sub(str, len, rest); | |||
}; | |||
|
|||
let rewrite_query = (loc, delim, query) => { | |||
let rewrite_query = (loc, delim, query, maybe_schema) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use labeled args here? It's getting pretty unreadable with more than 3 args.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe_schema
can then be ~schema=?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the parameter is explicitly an option in the downstream functions having it as ~schema=None
instead made things easier to read.
If you explicitly want it as ~schema=?
I can change it. But thought it didn't really matter myself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, I might have misunderstood the initial comment. Did you want all parameters to be named?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be all, can be just schema 🙂
I think this is ready now @baransu 🎉 |
@arnarthor Could you add it also to |
Thank you! LGTM 🎉 |
Releases as |
This adds an additional optional parameter to the ppx usage where you can locally override the desired schema to validate the query against.
This is fully backwards compatible with the old API and only extends it to allow for usage such as this
Reason
OCaml
By adding this extra parameter, the PPX now supports having multiple different GraphQL APIs in a single project without the need for yarn workspaces or similar solutions.