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

Update graphql.net to 4.6.1 #10782

Merged
merged 15 commits into from
Jan 10, 2022

Conversation

MikeKry
Copy link
Contributor

@MikeKry MikeKry commented Nov 30, 2021

Gatsby in version 3 and 4 is not working with current version of GraphQL in OrchardCore, so I have tried to update GraphQL.NET package.

I am currently testing it, so it does not break anything, right now it looks ok, but it definitely needs some more checking. I will be testing it further on existing projects.

It was quite a lot of work, so I decided to create a PR right away, so we can potentially merge it.

related to #10781
related also to #10760

@deanmarcussen
Copy link
Member

can you merge dev on this, so that the tests run.

also for infos here is the current pr to do this upgrade, with the outstanding work #9087 which maybe useful to see what has already been done, and is still needed to do

@carlwoodhouse
Copy link
Member

can you merge dev on this, so that the tests run.

also for infos here is the current pr to do this upgrade, with the outstanding work #9087 which maybe useful to see what has already been done, and is still needed to do

yeah sadly actual work keeps getting the better of me so i haven't had chance to work on it much in ages. Theres def stuff in the other PR we should use though; as i changed a lot to work to how graphql.net 4 expects in terms of DI, Permissions, etc and it should be more performant (as it removes some locks etc).

It would be good if we could maybe bring these 2 pr's together tho? take any of this which fixers outstanding issues in the other one ? @MikeKry

@MikeKry
Copy link
Contributor Author

MikeKry commented Nov 30, 2021

Ups.. I do not know why I could not find this PR when I searched for any update tasks/tickets..

So far my PR is working, I have found some problems when including into existing project and fixed them. I can take a look at other PR and use some of it. @carlwoodhouse do you have anything specific in mind that you know should be changed?

IDK if it would not be better to merge just an update so it would work with new versions of gatsby and then create tickets to update authorization etc. to new standards?

@MikeKry
Copy link
Contributor Author

MikeKry commented Nov 30, 2021

i think this pr also resolves - Dynamic fields are broken & Custom validators for max results need re-implementing to new spec & Check GraphQLFieldNameAttribute from original PR

@carlwoodhouse
Copy link
Member

yeah this is why its worth doing a comparision of the two (maybe target this at that branch as its on orchards github) and seeing where we are.

My main concern is a lot changed around document execution, dataloaders and some other threadsafety stuff ... but its been a while since i looked at it ...; so while this may compile and work .... (you've done an awesome job btw) - we need to make sure we dont break all the weird race conditions we had to fix in the first place (a lot of which are fixed in the newer versions)

@MikeKry
Copy link
Contributor Author

MikeKry commented Nov 30, 2021

@carlwoodhouse Thanks, I will take a look at it and compare what could be changed. I have done this using migration guides from 2->3 and 3->4 and used suggested solutions, so I hope it will be all OK, but it will definitely need someone who will check for know errors, as I test it only for errors that I know.

@deanmarcussen Is it enough to merge dev into my branch and push? or should i create a PR against dev? So far I am fixing some minor errors in tests but soon it will be fixed.

@carlwoodhouse
Copy link
Member

@carlwoodhouse Thanks, I will take a look at it and compare what could be changed. I have done this using migration guides from 2->3 and 3->4 and used suggested solutions, so I hope it will be all OK, but it will definitely need someone who will check for know errors, as I test it only for errors that I know.

@deanmarcussen Is it enough to merge dev into my branch and push? So far I am fixing some minor errors in tests but soon it will be fixed.

I mean a quick look through a lot is really similar; so you've done a great job (its no small thing which is why time has eluded me to finish the other PR heh); just think its worth bringing the two together so we get any optimizations etc from the other PR - and the unfinished stuff from here too. You seem to have done the DI wire-up somewhat different to me which i'd need to look at too.

@carlwoodhouse
Copy link
Member

these days we have to merge main not dev i think @deanmarcussen :P

@carlwoodhouse carlwoodhouse mentioned this pull request Nov 30, 2021
9 tasks
@carlwoodhouse
Copy link
Member

your text field changes fix the dynamic content issue on the other PR :)

@deanmarcussen
Copy link
Member

yes merge main, not dev :)

agriffard and others added 3 commits November 30, 2021 19:24
fix tests, remove services from graphqlcontext, fix where and orderby
@MikeKry
Copy link
Contributor Author

MikeKry commented Nov 30, 2021

@deanmarcussen @carlwoodhouse

Ok, I have merged items that made sense for me to merge from other PR, tests ran successfully locally, and I merged main into this branch, so I hope it could be ok.

@carlwoodhouse
Copy link
Member

carlwoodhouse commented Nov 30, 2021 via email

@Skrypt
Copy link
Contributor

Skrypt commented Nov 30, 2021

As long as it's not ready it should stay in a branch. Move it to the Orchard Core repository if you want but don't merge it in the main branch if it's creating regressions that need to be fixed first. So, move it to a graphql.net-4.6.1 branch in here. Then you may be able to compare the 2 branches locally.

@carlwoodhouse
Copy link
Member

carlwoodhouse commented Nov 30, 2021 via email

@Skrypt
Copy link
Contributor

Skrypt commented Nov 30, 2021

Well, as long as it's not merged on top of the main branch yet. 😉

@MikeKry
Copy link
Contributor Author

MikeKry commented Nov 30, 2021

@carlwoodhouse

I am okay with that as long as it will help with getting done ASAP :)
Do whatever you like with this PR or instruct me what should I do if you do not have rights to edit PR.

I would be thankful if it would get merged this week if possible, because it blocks for me two projects that are dependend on graphql.. and I am ready to assist with this if needed.

@carlwoodhouse carlwoodhouse changed the base branch from main to ag/graphql4 November 30, 2021 20:22
Copy link
Member

@carlwoodhouse carlwoodhouse left a comment

Choose a reason for hiding this comment

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

generally looks good, added a few comments and queries


// changed in V4
var encodedBytes = _utf8Encoding.GetBytes(await _writer.WriteToStringAsync(result));
await context.Response.Body.WriteAsync(encodedBytes, 0, encodedBytes.Length); // documentWriter causes problems when querying _schema
Copy link
Member

Choose a reason for hiding this comment

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

can you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

documentWriter.WriteAsync throws error when grahpql tries to get schema
"System.InvalidOperationException: Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead."

I did not find the cause and using workaround with AllowSynchronousIO does not seem ok to me.

Copy link
Member

Choose a reason for hiding this comment

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

this does ring a bell ... is this an issue in the ag/graphql4 branch currently then ? i have no idea why i changed it .... yours looks closer to the original tbh

Copy link
Member

Choose a reason for hiding this comment

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

Needs more thoughts, will buffer all responses, and the big ones could be an issue in terms of perf. Maybe at least use an ArrayPool?

src/docs/requirements.txt Show resolved Hide resolved
@MikeKry
Copy link
Contributor Author

MikeKry commented Dec 2, 2021

@carlwoodhouse

I have found some problems with update, I will try to resolve them and then push along with resolved change request

Fix where condition with nested objects, fix where conditions with AddScalarFilterFields
@MikeKry
Copy link
Contributor Author

MikeKry commented Dec 2, 2021

@carlwoodhouse

Pushed with fixes of nested where conditions and scalar filters => maybe there could be better solution, but this one ensures same functionality as we had before. There could be also unit test for nested where conditions.

I will continue testing, maybe some more errors will comes up.

@carlwoodhouse
Copy link
Member

carlwoodhouse commented Dec 2, 2021 via email

@@ -26,14 +26,13 @@ public RequiresPermissionValidationRule(IAuthorizationService authorizationServi

public async Task<INodeVisitor> ValidateAsync(ValidationContext validationContext)
{
var operationType = OperationType.Query;
// shouldn't we access UserContext from validationcontext inside MatchingNodeVisitor actions?
Copy link
Member

Choose a reason for hiding this comment

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

probably :)

@MikeKry
Copy link
Contributor Author

MikeKry commented Dec 13, 2021

@carlwoodhouse

Can I ask, is there anything waiting for me or can we move this forward?
We are using it on project for some time and no other bugs appeared.

@carlwoodhouse
Copy link
Member

@carlwoodhouse

Can I ask, is there anything waiting for me or can we move this forward? We are using it on project for some time and no other bugs appeared.

mostly thoughts on @sebastienros comment about the buffering of the response for the changes around the write and the negative performance implications ..

@MikeKry
Copy link
Contributor Author

MikeKry commented Dec 13, 2021

@carlwoodhouse

Do you want me to look at it or you will do it yourself?

@carlwoodhouse
Copy link
Member

carlwoodhouse commented Dec 13, 2021 via email

@MikeKry
Copy link
Contributor Author

MikeKry commented Dec 14, 2021

@carlwoodhouse @deanmarcussen

The problem with WriteAsync is in Serialize method in newtonsoft.json.
It is using synchronous Serialize internal method (https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json/JsonSerializer.cs#L1146)

which causes problems when writing directly into response.

I see two variants in here:
1/ overwrite this method - seems too complex
2/ serialize it into memory stream and then copy to response like this
image

@MikeKry
Copy link
Contributor Author

MikeKry commented Dec 15, 2021

I have pushed the change so you can all look at it. I think it is indeed better than before - WriteToString calls internally WriteAsync, so we have 1 less method call and we do not hold another variable in memory


private async Task WriteAsync<T>(Stream stream2, T value, IDocumentWriter documentWriter, CancellationToken cancellationToken = default)
{
// needs to be always async, otherwise __schema request is not working, direct write into response does not work as serialize is using sync method inside
Copy link
Member

Choose a reason for hiding this comment

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

Do you mean that somewhere in our grapqhl code with have a call to a Serialize method (NewtonSoft?) that is not async and this is triggered in IDocumentWriter.WriteaAsync.
If buffering is required, maybe use a smaller reused buffer instead of a single one as big as the payload, and pool it too? Another option might be to use BufferedStream between documentWriter and context.Response.Body.

await documentWriter.WriteAsync(stream, value);
stream.Seek(0, SeekOrigin.Begin);
await stream.CopyToAsync(stream2, cancellationToken);
using (MemoryStream stream = new MemoryStream())
Copy link
Member

Choose a reason for hiding this comment

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

Might use BufferedStream so not all the payload is serialized in memory.

@sebastienros
Copy link
Member

Looks promising. What's left to do, and is it replacing the other PR that is meant to migrate to 4.x ?

@carlwoodhouse
Copy link
Member

carlwoodhouse commented Dec 16, 2021 via email

@carlwoodhouse
Copy link
Member

carlwoodhouse commented Dec 16, 2021 via email

@MikeKry
Copy link
Contributor Author

MikeKry commented Jan 3, 2022

I did not encounter any other problems after using it locally for month.
If you want to use buffered stream, could you do it @carlwoodhouse or @deanmarcussen ? I just dont see how to use it in there.

@deanmarcussen
Copy link
Member

@carlwoodhouse

I'm confused, what's the story with this, it's targetting the other branch Antoine and you were working on ?

Can we merge it into there, so we can see review the two as one, and fix the stream buffering issue / look at what else is to do?

@carlwoodhouse
Copy link
Member

carlwoodhouse commented Jan 5, 2022 via email

@MikeKry
Copy link
Contributor Author

MikeKry commented Jan 10, 2022

and who can merge it? I can't..

@carlwoodhouse carlwoodhouse merged commit cc3eb91 into OrchardCMS:ag/graphql4 Jan 10, 2022
@carlwoodhouse
Copy link
Member

merged to ##9087

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.

7 participants