-
Notifications
You must be signed in to change notification settings - Fork 9
Null As for graphql #68
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
Conversation
The flag code looks good. To debug for this PR, workflow will be something like this:
^ that demonstrates how schema works on master. We want to be able to explicitly tell
|
I think there is an issue when building the schema map that is disjoint from the actual build schema stuff I changed, which is causing a basic test I wrote to fail, unsure of how best to go forward |
@@ -10,7 +10,7 @@ import ( | |||
func buildSchema(fromValue interface{}, dst *interface{}, params *FromExampleParams) error { | |||
switch v := fromValue.(type) { | |||
case nil: | |||
*dst = NewNull() | |||
*dst = NewNull(params) |
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.
schema infer --graphql
works like this right now
- Read incoming JSON/YAML/TOML, etc.
- Create an
jsonsch.Schema
object in memory - Call the method
js.ToGraphQLSchema()
to convert it to agraphqlsch.Schema
object - Serialize the
graphqlsch.Schema
object
All the logic of this PR looks correct, but it's in part 2 (from the numbering above^) of the codebase. Instead, part 3 should be modified. The lines we need to modify are here:
call to handlePrimitive: https://github.com/Confbase/schema/blob/master/jsonsch/jsonsch.go#L32
actual line that rejects null values in handlePrimitive: https://github.com/Confbase/schema/blob/master/jsonsch/jsonsch.go#L96
call to handleArraySchema: https://github.com/Confbase/schema/blob/master/jsonsch/jsonsch.go#L44
actual line that rejects null values: https://github.com/Confbase/schema/blob/master/jsonsch/jsonsch.go#L140
The codebase has zero documentation right now, so no question is a dumb question. Feel free to yell at me if anything is confusing
e2e_tests/infer.sh
Outdated
@@ -1750,6 +1750,16 @@ infer_json_null_graphql() { | |||
expect=`printf "error: failed to serialize schema\ncannot infer type of null value (see key 'is2004')"` | |||
} | |||
|
|||
infer_json_as_null_string_graphql() { | |||
output=`printf '{"myString":null}' | schema infer --graphql --as-null=string --omit-required=false 2>&1` |
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.
Test looks good except we don't need --omit-required=false
since it has no bearing on graphql schemas. When that flag is true, the "required" field is omitted from JSON schemas.
Alright, I think this should be good to merge 😄 |
Addressing #62
I added the flag for --null-as and made some assumptions about how the implementation should work, however it should be trivial to switch that logic if you have a better/different idea in mind