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

feat(compiler): Add SchemaCoordinate::lookup methods #803

Merged
merged 4 commits into from
Jan 12, 2024

Conversation

goto-bus-stop
Copy link
Member

@goto-bus-stop goto-bus-stop commented Jan 11, 2024

All the coordinate types have a .lookup(&schema) method.

I omitted the SchemaLookup trait that used to be in #757. It was only there to support schema.lookup(&coord), but that's exactly the same as writing coord.lookup(&schema), and it's simpler not to have both.

assert!(coord!(ObjectDefault.someField(privateArg:)).lookup(&schema).is_ok());
// vs.
assert!(schema.type_field("ObjectDefault", "someField").is_some_and(|f| f.arguments.iter().any(|arg| arg.name == "privateArg")));

Type attribute coordinate syntax can refer to object or interface field definitions, input
field definitions, and enum values. TypeAttributeCoordinate::lookup returns an enum to
account for those possibilities. To look up a specific kind of type attribute, there are
convenience methods:

  • TypeAttributeCoordinate::lookup_field for object or interface fields
  • TypeAttributeCoordinate::lookup_input_field for input fields
  • TypeAttributeCoordinate::lookup_enum_value for enum values

This should help with writing assertions in tests where you normally already know what
type you expect.

All the coordinate types have a `.lookup(&schema)` method returning the
narrowest possible type.
Copy link
Contributor

@SimonSapin SimonSapin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having lookup_field / lookup_input_field / lookup_enum_value is a great idea. I’m less convinced about introducing two enums just for TypeAttributeCoordinate::lookup and SchemaCoordinate::lookup to exist. I struggle to imagine a use case where you don’t know in advance what kind of item you want to look up. But having them doesn’t "cost" all that much.

@goto-bus-stop
Copy link
Member Author

It's a fair point. I think SchemaCoordinate::lookup has a use case in developer tooling where you could get a schema coordinate from user input, while TypeAttributeCoordinate::lookup really just exists for completeness (but it's pretty much free as lookup_ref would still exist to support SchemaCoordinate::lookup).

@goto-bus-stop goto-bus-stop merged commit 98dfb20 into main Jan 12, 2024
12 checks passed
@goto-bus-stop goto-bus-stop deleted the schema-lookup branch January 12, 2024 16:49
@goto-bus-stop goto-bus-stop mentioned this pull request Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants