NavidK0 / SimpleGraphQL-For-Unity

A simple graphQL client that allows one to use .graphql files (or code) for queries, mutations, and subscriptions with Unity.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Still issues with code stripping on WebGL

johanhelsing opened this issue · comments

I submitted a fix for a webgl stripping issue earlier, but it turns out it wasn't enough.

There are no errors. The deserialized responses that are returned have no errors, but the Response.Data field is also null even though I can see that there is data in the response body in the browser inspector. The code that accesses stuff inside the Data field, i.e. Response.Data.gameSession.id also happily converts to null, so I didn't really get any errors for these things, which is why I didn't notice earlier.

I managed to make it work by adding a link.xml file to disable stripping

<linker>
    <assembly fullname="LastAbyss.SimpleGraphQL.Runtime" preserve="all" />
    <assembly fullname="AssemblyCSharp" preserve="all" />
</linker>

However, it also increased build size quite badly... I'll do some more tests and see if I can be more specific.

I guess we should either remove the anonymous api again or add a big fat warning to the readme?

Hmm... increasing build size by a large amount is a problem for sure, especially for WebGL/Android/iOS since you want to keep it as small as possible.

Are the errors happening only on WebGL, or is it a problem across platforms? If it's only a WebGL problem, then we can add a warning. If it's a widespread platform issue, then we should probably remove the anonymous API for now until we can find a better solution.

I am still concerned by the build size though, so if the build size increases by a lot for all platforms, then we should probably keep it out for now.

I was a bit quick. Doesn't look like there is much difference in size after all, and i managed a quite narrow entry for link.xml.

It can't be added to the package though, it will have to be done by projects using this library, or we would have to ship dlls instead. See https://github.com/jilleJr/Newtonsoft.Json-for-Unity/wiki/Embed-link.xml-in-UPM-package

If we have to, shipping a DLL is probably the best option so that there is as little friction in installation as possible for the end-user.

I found a way to inject link.xml without precompiling :)

It's pretty ugly, but it works.

https://github.com/LastAbyss/SimpleGraphQL-For-Unity/compare/master...johanhelsing:feature/refactor-and-fix-stripping-issues?expand=1#diff-8d57fe4075a9d32d824af7f2ffac584bf95cbcbe40aa570e542497c5c0552a48

Edit: After doing some refactoring (also in the link above) I was also able to narrow the contents of link.xml quite a bit:

<linker>
    <assembly fullname="LastAbyss.SimpleGraphQL.Runtime">
        <type fullname="SimpleGraphQL.Response*" />
        <type fullname="SimpleGraphQL.Request*" />
    </assembly>
</linker>

I see, hmm. Using the GUID feels quite fragile, I must admit. I wonder if there's a better way just using a relative path directly to the link.xml file and then providing the full path from there? We could just stick it inside our project, copy it to their project in Plugins/SimpleGraphQL before build using a IPreprocessBuildWithReport.OnPreprocessBuild?