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

Upgrade GraphQL to 8.2 #16736

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open

Upgrade GraphQL to 8.2 #16736

wants to merge 35 commits into from

Conversation

MikeAlhayek
Copy link
Member

@MikeAlhayek MikeAlhayek commented Sep 16, 2024

Fixes #16826.

@MikeAlhayek
Copy link
Member Author

@hyzx86 you upgraded GraphQL package last time. You may be more familiar with this. Can you please check this out?

@hishamco
Copy link
Member

IMHO we need to stop bumping the packages ourselves like you said before until the Dependabot is fixed

@MikeAlhayek
Copy link
Member Author

IMHO we need to stop bumping the packages ourselves like you said before until the Dependabot is fixed

The Dependabot is fixed. But it can't do breaking changes like this one. These will need to always be done manually.

@hishamco
Copy link
Member

I thought it was straightforward

Anyhow, to try to fix the broken unit tests. @hyzx86 your help appreciated

@hyzx86
Copy link
Contributor

hyzx86 commented Sep 18, 2024

This problem seems to be related to dynamically generated filtering conditions.

Sorry, I'm busy with other projects recently. It's at a critical stage, and I may not have time to deal with this problem for some time.

@hishamco
Copy link
Member

Thanks @hyzx86

@MikeAlhayek can you handle this? Or we might need help from @carlwoodhouse or @mdameer who worked recently on some GraphQL PRs

@MikeAlhayek
Copy link
Member Author

This is going to be a breaking change and should not be part of 2.x. We should wait until 3 before doing this as we have to set ResolvedType instead of Type on all fields (including custom fields in external projects).

@hishamco
Copy link
Member

So, let us defer this PR then

Copy link
Contributor

This pull request has merge conflicts. Please resolve those before requesting a review.

Copy link
Contributor

This pull request has merge conflicts. Please resolve those before requesting a review.

@MikeAlhayek MikeAlhayek added this to the 3.0 milestone Nov 21, 2024
@MikeAlhayek
Copy link
Member Author

@sebastienros this is ready

@hishamco
Copy link
Member

The build is still fail

Copy link
Contributor

This pull request has merge conflicts. Please resolve those before requesting a review.

Copy link
Contributor

This pull request has merge conflicts. Please resolve those before requesting a review.

Copy link
Contributor

This pull request has merge conflicts. Please resolve those before requesting a review.

@gvkries gvkries changed the title Upgrade GraphQL to 8.0.2 Upgrade GraphQL to 8.2 Nov 22, 2024
Copy link
Contributor

@gvkries gvkries left a comment

Choose a reason for hiding this comment

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

Nice work, thanks @MikeAlhayek. I've added some comments, but I've not fully tested this yet.

// Clean Query, Mutation and Subscription if they have no fields
// to prevent GraphQL configuration errors.

if (schema.Query.Fields.Count == 0)
if (schema.Query?.Fields is null || schema.Query.Fields.Count == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Query, Mutation and Subscription can't be null here, they are all set above.

Description = fieldDescriptor.Description,
Type = fieldDescriptor.FieldType,
ResolvedType = fieldDescriptor.ResolvedType,
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand the changes here correctly, we can get rid of the assignment Type = FieldType. The type has been replaced by ResolvedType because the fields are added during schema initialization. Is that assumption correct?

public Func<ContentElement, object> FieldAccessor { get; set; }
public string Index { get; set; }
public Type IndexType { get; set; }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer to leave this class here as a nested type, because it is an implementation detail of the ContentFieldsProvider only.

private readonly GraphQLContentOptions _graphQLContentOptions;

internal IStringLocalizer S;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't these be private, or does the PoExtractor depend on those fields being internal?

@@ -117,6 +117,7 @@ private static FieldType BuildSchemaBasedFieldType(Query query, JsonNode querySc
Name = nameLower,
Description = description,
Type = typeof(StringGraphType),
ResolvedType = new StringGraphType(),
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be necessary in an ISchemaBuilder. Using the resolved type is only mandatory if we are adding fields later on. See https://graphql-dotnet.github.io/docs/migrations/migration8/#30-code-classlanguage-textgraphtypeinitializecode-method-is-now-called-after-initialization-is-complete
This applies to the other occurrences as well.


private readonly Dictionary<Type, IGraphType> graphTypes = new();

private IGraphType CreateGraphType(Type type)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please double check if we absolutely need to instantiate all of the types here as well. It actually depends on when we are adding those fields.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. This is part of the transition from v7 to v8. There are Schema validation that happens, and because we create the dynamic field in the Initialize method instead of the constructor, we get errors like this

The field 'Amount' of an Input Object type 'PricePartWhereInput' must have non-null 'ResolvedType' property for all types in the chain.

You may want to try to not set the ResolvedType and see the error.

@@ -34,9 +34,6 @@ public override void Initialize(ISchema schema)
}
}

// Part is not required here anymore, do not keep it alive.
_part = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need to keep this referenced. The schema is a singleton, which effectively keeps that reference alive forever.

Copy link
Member Author

Choose a reason for hiding this comment

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

Where is it being registered as singleton? The DynamicPartGraphType is instantiated from DynamicContentTypeBuilder. I don't think it lives for a long time.

Copy link
Contributor

Choose a reason for hiding this comment

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

The graph types are kept alive in the schema, IIRC.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure. SchemaService is a singleton and hold ISchema instances. But part is not something we keep in the Schema. I could be wrong, but please double check before we add it back.

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.

Upgrade GraphQL to 8.x.x
5 participants