Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Validation for relationships fails on valid case #2019

Closed
wtrocki opened this issue Sep 9, 2020 · 13 comments
Closed

Validation for relationships fails on valid case #2019

wtrocki opened this issue Sep 9, 2020 · 13 comments
Labels
bug Something isn't working triage

Comments

@wtrocki
Copy link
Contributor

wtrocki commented Sep 9, 2020

Problem with OpenVolunteerModel

Error: Volunteer.actions and VolunteerAction.volunteer 'key' annotations are different. Ensure both are the same or remove one so that it can be generated.

https://github.com/aerogear/OpenVolunteerPlatform/blob/master/platform/server/model/main.graphql#L38-L41

The action doesn't have a key specified and ManyToOne side has (this was just copied from the generated schema for visibility of the field in the schema)

Error is confusing as key is not there. Removing key from manyToOne will fix it.

@wtrocki wtrocki added the enhancement New feature or request label Sep 9, 2020
@machi1990
Copy link
Contributor

/cc @craicoverflow, @machi1990
Automatically generated comment to notify maintainers

@wtrocki
Copy link
Contributor Author

wtrocki commented Sep 9, 2020

I'm not sure if there is some fix here.

@wtrocki
Copy link
Contributor Author

wtrocki commented Sep 9, 2020

This is a bug. Little bit debugging showed me that result schema has some extra annotations generated and ends up with 2 annotations under single object:

Screenshot 2020-09-09 at 11 52 59

@wtrocki wtrocki added bug Something isn't working and removed enhancement New feature or request labels Sep 9, 2020
@wtrocki
Copy link
Contributor Author

wtrocki commented Sep 9, 2020

So trick that I have done is:

  • Generate schema
  • When to schema to take generated fields and include them into model (they should be ok to be in the model.
  • Generate code:
<b>Generation failed: Error: Volunteer.actions and VolunteerAction.volunteer 'key' annotations are different. Ensure both are the same, or remove one so that it can be generated.</b>

@wtrocki
Copy link
Contributor Author

wtrocki commented Sep 9, 2020

See also #2020

@craicoverflow
Copy link

What happens when you remove all manyToOne annotations from the data model? It should succeed

@wtrocki
Copy link
Contributor Author

wtrocki commented Sep 9, 2020

It will fail validation (unless this change is applied)

@craicoverflow
Copy link

Can you show me the output?

@craicoverflow
Copy link

Can you reproduce this error using the models from the templates? They are smaller and more focused so it is easier to see why the error occurs - as in OVP the model is large and there could be other schema errors.

@machi1990
Copy link
Contributor

So trick that I have done is:

  • Generate schema
  • When to schema to take generated fields and include them into model (they should be ok to be in the model.
  • Generate code:
<b>Generation failed: Error: Volunteer.actions and VolunteerAction.volunteer 'key' annotations are different. Ensure both are the same, or remove one so that it can be generated.</b>

I think this

if (oneToManyMetadata?.key !== corresspondingManyToOneMetadata?.key) {

will need changing so that it compares the two keys if they are both defined (read as user defined values) since if they are not defined they'll be generated with key info:

What's your thoughts on this @craicoverflow ?

@craicoverflow
Copy link

will need changing so that it compares the two keys if they are both defined (read as user defined values)

That sounds better - this way you could have a manyToOne annotation with the key property and it would get updated, am I right?

I think these patches we make to RelationshipBuilder will not make the class any easier to work with, and I wonder whether #2023 should be focused on, as this particular issue raised I don't think is the root of the problem.

@machi1990
Copy link
Contributor

will need changing so that it compares the two keys if they are both defined (read as user defined values)

That sounds better - this way you could have a manyToOne annotation with the key property and it would get updated, am I right?

I think these patches we make to RelationshipBuilder will not make the class any easier to work with, and I wonder whether #2023 should be focused on, as this particular issue raised I don't think is the root of the problem.

+1 on this.

@craicoverflow
Copy link

Closing as the case was valid and working as intended (it actually caught an invalid relationship association in the model). There is an issue #2023 to track a general improvement of relationships.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants