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

fix #2485 Defined type from a basic type should not need scalar #2486

Merged
merged 3 commits into from
Jan 13, 2023
Merged

fix #2485 Defined type from a basic type should not need scalar #2486

merged 3 commits into from
Jan 13, 2023

Conversation

mstephano
Copy link
Contributor

@mstephano mstephano commented Dec 23, 2022

Fixes #2485 : Defined type from a basic type should not require a scalar

Before this PR, running go generate when using a defined type from a basic type (string, int, boolean, float) that are then used in go struct will display an error message saying <type> is incompatible with <named_type>. We would then need to create a scalar with its related MarshalFunc and UnmarshalFunc to remove the error message. This will lead to many copy-pastes of the same MarshalFunc and UnmarshalFunc with only the type being changed.

After this PR gqlgen will support the following cases (see Go spec: https://go.dev/ref/spec#Type_declarations):

  • GraphQL scalar with custom marshalling/unmarshalling
  • a type definition from a basic type without a custom scalar and MarshalFunc and UnmarshalFunc
  • an alias declaration without a custom scalar and MarshalFunc and UnmarshalFunc

I have:

  • Added tests covering the bug / feature (see testing)
  • Updated any relevant documentation (see docs)

@coveralls
Copy link

coveralls commented Dec 23, 2022

Coverage Status

Coverage: 75.583% (-0.05%) from 75.636% when pulling 87e11fb on mstephano:master into 43c9a1d on 99designs:master.

Comment on lines 14 to +16
isBanned: Banned!
isLoginBanned: Boolean!
isQueryBanned: Boolean!
Copy link
Contributor Author

@mstephano mstephano Dec 24, 2022

Choose a reason for hiding this comment

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

As per Go spec: https://go.dev/ref/spec#Type_declarations:

  • isBanned is a scalar with custom marshalling/unmarshalling
  • isLoginBanned is a type definition
  • isQueryBanned is an alias declaration

Making sure my PR is working fine in any of these situations.

@StevenACoffman StevenACoffman changed the title fix #2485 remote named basics should not need scalar fix #2485 Defined type from a basic type should not need scalar Jan 12, 2023
@@ -1,3 +1,25 @@
type RemoteModelWithOmitempty {
newDesc: String
}

type DummyUserWithRemoteNamedBasics {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you change references like this from "RemoteNamedBasics" to DefinedTypeFromBasics?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the code and removed "DummyUserWith", just kept "DefinedTypeFromBasics".

newFloat64: Float!
newID: ID!

### BELOW ARE NOT SUPPORTED AS BASIC - MUST CREATE SCALAR WITH MARSHALFUNC AND UNMARSHARLFUNC ###
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this comment still correct?

Copy link
Contributor Author

@mstephano mstephano Jan 12, 2023

Choose a reason for hiding this comment

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

Yes, for some reason, the ones below still have the message is incompatible with, and I am not sure why. I could spend some time to investigate if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I did a quick test and the error message is not ..incompatible with.. but Undefined type uint64 coming from gqlparser.

@StevenACoffman StevenACoffman merged commit 867b61a into 99designs:master Jan 13, 2023
@StevenACoffman
Copy link
Collaborator

Thanks so much for your work on this! If you could look into why those types require a scalar, I would appreciate a follow-up.

@mstephano
Copy link
Contributor Author

@StevenACoffman FYI, I found the issue with those types that require a scalar. I will send a PR soon after I finalize the tests.

StevenACoffman added a commit that referenced this pull request Mar 20, 2023
Signed-off-by: Steve Coffman <steve@khanacademy.org>
StevenACoffman added a commit that referenced this pull request Mar 20, 2023
Signed-off-by: Steve Coffman <steve@khanacademy.org>
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.

Defined type from a basic type should not need a mandatory scalar + MarshalFunc and UnmarshalFunc
3 participants