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

Add support for interface implementing interface #981

Merged

Conversation

filosganga
Copy link
Contributor

@filosganga filosganga commented Mar 29, 2023

This is an initial support for #567 and supersede #597 that is based on very old base

The rendering has been a bit challenging and I took a non-standard path there

Copy link
Contributor

@yanns yanns left a comment

Choose a reason for hiding this comment

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

Very cool to see progress here!

@filosganga
Copy link
Contributor Author

@yanns This is pretty much done but there are a couple of missing validations that I don't know how to handle:

All the implementing fields must be declare
When a type or an interface implement another interface, all the implementing fields must be declared. This is not currently validated even without interfaces implementing interfaces, so can it be addressed in a follow-up PR?

The implementation hierarchy MUST not include loops
I have managed to check for interfaces implementing themselves, however is very complex to spot issues like this:

interface Foo implement Baz {
  foo: String
}

interface Bar implement Foo{
  bar: String
  foo: String
}

interface Baz implement Bar & Foo {
  baz: String
  bar: String
  foo: String
}

Because the materializer/builder goes in SO when trying to resolve the types. Is there a way to validate the ast before running the materializer/builder?

Cheers

@yanns
Copy link
Contributor

yanns commented Mar 29, 2023

All the implementing fields must be declare When a type or an interface implement another interface, all the implementing fields must be declared. This is not currently validated even without interfaces implementing interfaces, so can it be addressed in a follow-up PR?

Yes

The implementation hierarchy MUST not include loops I have managed to check for interfaces implementing themselves, however is very complex to spot issues like this:

interface Foo implement Baz {
  foo: String
}

interface Bar implement Foo{
  bar: String
  foo: String
}

interface Baz implement Bar & Foo {
  baz: String
  bar: String
  foo: String
}

Because the materializer/builder goes in SO when trying to resolve the types. Is there a way to validate the ast before running the materializer/builder?

I'm not sure. I'm thinking of https://github.com/sangria-graphql/sangria/pull/966/files where some validation is done on the AST directly. Does this help?

@filosganga
Copy link
Contributor Author

All the implementing fields must be declare When a type or an interface implement another interface, all the implementing fields must be declared. This is not currently validated even without interfaces implementing interfaces, so can it be addressed in a follow-up PR?

Yes

The implementation hierarchy MUST not include loops I have managed to check for interfaces implementing themselves, however is very complex to spot issues like this:

interface Foo implement Baz {
  foo: String
}

interface Bar implement Foo{
  bar: String
  foo: String
}

interface Baz implement Bar & Foo {
  baz: String
  bar: String
  foo: String
}

Because the materializer/builder goes in SO when trying to resolve the types. Is there a way to validate the ast before running the materializer/builder?

I'm not sure. I'm thinking of https://github.com/sangria-graphql/sangria/pull/966/files were some validation is done on the AST directly. Does this help?

Yep, I think so.

Also, thank you to have allowed the workflow to run, I need to fix a few things :)

@filosganga filosganga force-pushed the 567-interface-implement-interface branch from cc31b4d to 9f5dc36 Compare March 29, 2023 13:17
@yanns
Copy link
Contributor

yanns commented Mar 29, 2023

[error] (sangria-core / Compile / scalafmtCheck) scalafmt: 1 files must be formatted (/home/runner/work/sangria/sangria/modules/core)

@filosganga filosganga marked this pull request as ready for review March 29, 2023 20:13
@filosganga
Copy link
Contributor Author

@yanns This is ready to review. However, it is impossible to retain binary compatibility because Sangria uses case classes with default values. I have added the mima filters but I think a major version bump may be needed

All the implementing fields must be declare When a type or an interface implement another interface, all the implementing fields must be declared. This is not currently validated even without interfaces implementing interfaces, so can it be addressed in a follow-up PR?

Yes
Actually, I saw that in (

// we allow object type to inherit fields from the interfaces
// without explicitly defining them, but only when it is not
// defined though SDL.
) Sangria allows to avoid defining all the inherited fields.

I have implemented cycle detection in the AST before being materialised

@yanns
Copy link
Contributor

yanns commented Mar 30, 2023

Really cool, I'll have a look at this.
Yes, I think I'll make a major version bump.

@filosganga
Copy link
Contributor Author

If you do a major version bump, I can remove the apply methods that meant to keep source compatibility or limit the changes.

Thank you for your time

Copy link
Contributor

@yanns yanns left a comment

Choose a reason for hiding this comment

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

Beautiful PR, with lot of tests! 💯

description: Option[StringValue],
comments: Vector[Comment],
trailingComments: Vector[Comment],
location: Option[AstLocation]): InterfaceTypeDefinition = new InterfaceTypeDefinition(
Copy link
Contributor

Choose a reason for hiding this comment

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

💯 for taking care of "source compatibility".
I've checked that this apply is only used in tests.

modules/ast/src/main/scala/sangria/ast/QueryAst.scala Outdated Show resolved Hide resolved
@yanns
Copy link
Contributor

yanns commented Mar 30, 2023

If you do a major version bump, I can remove the apply methods that meant to keep source compatibility or limit the changes.

Good point.
We should still try not to break user code if possible. It's sometimes feasible with default values. But sometimes we need those new apply methods.

@yanns
Copy link
Contributor

yanns commented Mar 30, 2023

For reference, this is in the spec since https://github.com/graphql/graphql-spec/blob/main/changelogs/October2021.md

@filosganga
Copy link
Contributor Author

Good point. We should still try not to break user code if possible. It's sometimes feasible with default values. But sometimes we need those new apply methods.

Fair point

@yanns yanns added this pull request to the merge queue Mar 30, 2023
Merged via the queue into sangria-graphql:main with commit 011f3d2 Mar 30, 2023
@yanns
Copy link
Contributor

yanns commented Mar 30, 2023

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