Comments (9)
Hi Navid!
The reason that I originally wrote that WebGL "may or may not" work properly is precisely because of the problem with websockets on WebGL. The websockets are just used for subscriptions though, so if you don't need those, then it works just fine. (But most people probably use GraphQL for the subscription part.)
Ok, I think I get it :) Just hoping we can change "If you do not need subscriptions, WebGL may work just fine." to "If you do not use subscriptions, WebGL will work just fine.".
we at Last Abyss don't use WebGL with real-time networking capabilities for anything at the moment, so it's hard to say if I would be able to test a proper WebGL project with GraphQL integration.
I'm using mutations and queries using this library in a small game I'm working on. So far no issues with WebGL. I can update the readme if nothing bad happens the next few days.
Alternatively adding CySharp.UniTask as an optional dependency and have ifdefs to alias to it installed.
This is something that could be added. Perhaps some kind of #ifdef with an installer if WebGL is detected, and then an #else for uninstalling the dependency when the platform is switched again.
Great, then we have a backup plan of sorts :) Hopefully we don't need it 🤞. I think as long as we don't use anything that starts new threads (like Task.Delay
for instance) we should be good, though I'm no expert on this.
Add some jslib helper code to support subscriptions
This can definitely be supported with the solution proposed above. I am not entirely familiar with calling native browser functionality from Unity WebGLs, so perhaps you could give some insight on how this works?
Nice :)
I did it like this in another project
#if UNITY_WEBGL
#if !UNITY_EDITOR
using System.Runtime.InteropServices;
#endif
using UnityEngine;
public class WebGLHelpers : MonoBehaviour
{
#if UNITY_EDITOR
public static int AddOpenUrlInNewTabClickHandler(string url)
{
Debug.LogWarning("JavaScript doesn't work in the editor. Make a build or switch platforms.");
return 0;
}
#else
[DllImport("__Internal")]
public static extern int AddOpenUrlInNewTabClickHandler(string url);
#endif
}
#endif // UNITY_WEBGL
Then the actual js is in a .jslib file which is following a special unity convention and has access to the browser apis.
As for subscriptions, I'm not completely sure if I have the need for it yet, I'll have a go at it if/when I need it.
@johanhelsing Would you like write access to the repo? Your contributions have already been very valuable to the project.
Thanks! That would be really cool 😄
I have some questions regarding how you like to run things, but I'll open a separate issue for this to not spam this thread in case anyone else wants to have a go at the rest of the WebGL stuff later :)
from simplegraphql-for-unity.
@johanhelsing On second thought, it might actually be worth rewriting the socket code entirely using NativeWebSocket instead? It seems it uses System.Net.Websockets anyways, so it should work just fine on consoles... (I think...)
Then we'd be able to keep the codebase clean while also getting WebGL/HTML5 support for "free".
from simplegraphql-for-unity.
Hi Johan!
I made this for the same reasons as you say, I felt that writing GraphQL queries within the Unity GUI was cumbersome and slow. I much preferred writing GraphQL files and testing them within GraphiQL.
The reason that I originally wrote that WebGL "may or may not" work properly is precisely because of the problem with websockets on WebGL. The websockets are just used for subscriptions though, so if you don't need those, then it works just fine. (But most people probably use GraphQL for the subscription part.)
Now, we at Last Abyss don't use WebGL with real-time networking capabilities for anything at the moment, so it's hard to say if I would be able to test a proper WebGL project with GraphQL integration. I would definitely need help with that. I also would like to add some proper tests into the package at some point, but dev bandwidth is low for us right now.
We currently don't even use GraphQL for any of our active projects at the moment, so testing this package is already fairly difficult. If you would like to try out this package (and figure out issues with WebGL), you are more than welcome to! We can figure out solutions for WebGL as we get to them.
As for my thoughts:
https://gamedev.stackexchange.com/questions/176842/how-can-i-use-websockets-in-a-unity-webgl-project
The solution proposed here is definitely interesting. If it's unobtrusive to the other platforms, we could definitely add this in with no issues.
-
Adding CySharp.UniTask as a dependency if there are issues with Task on WebGL
I wouldn't do this directly, see below. -
Alternatively adding CySharp.UniTask as an optional dependency and have ifdefs to alias to it installed.
This is something that could be added. Perhaps some kind of #ifdef with an installer if WebGL is detected, and then an #else for uninstalling the dependency when the platform is switched again. -
Add some jslib helper code to support subscriptions
This can definitely be supported with the solution proposed above. I am not entirely familiar with calling native browser functionality from Unity WebGLs, so perhaps you could give some insight on how this works?
from simplegraphql-for-unity.
@johanhelsing Would you like write access to the repo? Your contributions have already been very valuable to the project.
from simplegraphql-for-unity.
@NavidK0 This project looks like it should solve it: https://github.com/endel/NativeWebSocket
Would you be ok with adding a dependency?
from simplegraphql-for-unity.
@NavidK0 This project looks like it should solve it: https://github.com/endel/NativeWebSocket
Would you be ok with adding a dependency?
This project looks good, no DLLs required. Yeah, we can add this for WebGL support. I would only use it for WebGL support and not rewrite the core system so that platforms like game consoles aren't affected.
from simplegraphql-for-unity.
hey did you start doing this? I think this is the way to go, too.
from simplegraphql-for-unity.
hey did you start doing this? I think this is the way to go, too.
Me? No, haven't had a need graphql for a while, so feel free to take the lead if you want to!
from simplegraphql-for-unity.
I have not added new features to this library either, as we haven't required GraphQL in our games for a long while. Overall, I'd say it's in a stable state though.
Unfortunately, changing the internal web socket to use NativeWebSocket requires much testing that I don't have the time for. As Johan says though, feel free to add it in if you want it!
from simplegraphql-for-unity.
Related Issues (20)
- GraphQLConfig Files list doesn't accept .graphql files HOT 4
- Subscribe API needs to be updated to match Send API
- Comments need to be updated to reflect new API changes
- Assembly with name 'Tests' already exists (Packages/com.lastabyss.simplegraphql/Tests/Runtime/LastAbyss.SimpleGraphQL.Runtime.Tests.asmdef) HOT 1
- Add Tests for subscriptions
- Improve documentation
- A Native Collection has not been disposed, resulting in a memory leak. Allocated from: Unity.Collections.NativeArray HOT 1
- Use NativeWebSocket lib for WebSockets
- Closing Subscriptions to Websocket HOT 4
- Slower Calls After Update HOT 6
- Wrong URL in the documentation HOT 2
- Subscriptions didn't work with my GraphQL Server until I added an empty Payload to the connection init. HOT 3
- error CS0539: 'LinkXmlInjector.OnBeforeRun(BuildReport, UnityLinkerBuildPipelineData)' in explicit interface declaration is not found among members of the interface that can be implemented HOT 6
- Headers not working in subscriptions with aws appsync HOT 6
- Subscriptions not found using FindQuery (if placed together wit other graphql statements) HOT 2
- No support for arrays in GraphQL Input types?
- Old projects not compiling after upgrading minor version HOT 2
- Problems when subscriptions complete HOT 8
- Question, handling different response Types HOT 1
- definition for 'Result' and no accessible extension method 'Result' accepting a first argument of type 'Response<<anonymous type: HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simplegraphql-for-unity.