chkimes / graphql-net

Convert GraphQL to IQueryable
MIT License
891 stars 86 forks source link

Using GraphQL under Sharepoint ISAPI (WCF) #69

Closed MakaBuka closed 7 years ago

MakaBuka commented 7 years ago

Hi guys, By business request, I need host my WCF service (that uses GraphQL.net) under sharepoint (and it deploys to ISAPI folder).

Unfortunately, I get some strange error that related to graph.dll - error CS0012: The type 'GraphQL<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'GraphQL.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

It occurs when I try to CreateDefaultContext. In case when it is hosted just under IIS it works fine.

Maybe u can give a hint why it happens.

Thx, D.

chkimes commented 7 years ago

What version of SharePoint are you running it on? SharePoint releases lag behind .NET versions, and this library needs .NET 4.6.

Can you post the error that you're seeing?

MakaBuka commented 7 years ago

So, I'm using sharepoint 2016.

First of all, I have a couple warnings on build/deploy to sharepoint - https://www.screencast.com/t/GPWVeRAi

Secondary, I'm trying to init context for GraphQL (here's screenshot of this method - https://www.screencast.com/t/GV25cDQyr2 )

And finally, here's error in debug mode - http://screencast.com/t/Xo4c19eugY

BTW, I've tried to add these libs (GraphQL and related libs) to GAC - http://screencast.com/t/Zaa5wOlYU And I got an exception - http://screencast.com/t/clSwhTVmF

'accManager.CreateDefaultContext()' threw an exception of type 'System.IO.FileLoadException' Data: {System.Collections.ListDictionaryInternal} FileName: "GraphQL.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" FusionLog: "" HResult: -2146234300 HelpLink: null InnerException: null Message: "Could not load file or assembly 'GraphQL.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)" Source: null StackTrace: null TargetSite: null

UPD2: So, I've compiled and signed GraphQL.dll and upload it to GAC. Unfortunately, I've got an error - http://screencast.com/t/ruVbpkLlNmpc

'accManager.CreateDefaultContext()' threw an exception of type 'System.IO.FileNotFoundException' Data: {System.Collections.ListDictionaryInternal} FileName: "GraphQL.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4bf04ea77ace47de" FusionLog: "=== Pre-bind state information ===\r\nLOG: DisplayName = GraphQL.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4bf04ea77ace47de\n (Fully-specified)\r\nLOG: Appbase = file:///C:/inetpub/wwwroot/wss/VirtualDirectories/64000/\r\nLOG: Initial PrivatePath = C:\inetpub\wwwroot\wss\VirtualDirectories\64000\bin\r\nCalling assembly : WCF_GraphQL_CSOM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fbfc095a047a5a40.\r\n===\r\nLOG: This bind starts in default load context.\r\nLOG: Using application configuration file: C:\inetpub\wwwroot\wss\VirtualDirectories\64000\web.config\r\nLOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config\r\nLOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.\r\nLOG: The same bind was seen before, and was failed with hr = 0x80070002.\r\n" HResult: -2147024894 HelpLink: null InnerException: null Message: "Could not load file or assembly 'GraphQL.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4bf04ea77ace47de' or one of its dependencies. The system cannot find the file specified." Source: null StackTrace: null TargetSite: null

Thx, D.

chkimes commented 7 years ago

Looks like SharePoint isn't happy that the assemblies aren't signed. I've updated GraphQL on NuGet to version 0.3.2, which should be equivalent to 0.3.1 but with the included assemblies signed.

chkimes commented 7 years ago

Hmm, I think that the GraphQL.Net assembly works fine now, but maybe one of its dependencies is not signed. We reference a library called FParsec-Pipes that is likely not signed. You may want to make an issue on that project to sign the assemblies. Optionally, you can compile and sign that yourself as well.

MakaBuka commented 7 years ago

Hi Ckimes89,

First of all, thank you for prompt update.

I've put all these libs (graphql and related libs) to GAC and...and it didn't make me happy.

I've got an error on executing my graphql query:

graphQLContext.ExecuteQuery(relex) 'graphQLContext.ExecuteQuery(relex)' threw an exception of type 'System.MissingMethodException' ClassName: null Data: {System.Collections.ListDictionaryInternal} HResult: -2146233069 HelpLink: null InnerException: null MemberName: null Message: "Method not found: 'ParserResult2<!!0,Microsoft.FSharp.Core.Unit> FParsec.CharParsers.run(Microsoft.FSharp.Core.FSharpFunc2<FParsec.CharStream1<Microsoft.FSharp.Core.Unit>,FParsec.Reply1<!!0>>, System.String)'." Signature: null Source: "GraphQL.Parser" StackTrace: " at GraphQL.Parser.Parser.parseDocument(String source)\r\n at GraphQL.Parser.GraphQLDocument1.Parse(ISchema1 schema, String source)\r\n at GraphQL.Net.GraphQL1.ExecuteQuery(String queryStr, TContext queryContext)\r\n at GraphQL.Net.GraphQL1.ExecuteQuery(String queryStr)" TargetSite: {Document parseDocument(System.String)}

BTW, FSharp.Core (v.4.3) is also inside GAC - https://www.screencast.com/t/xl3C5F9A

Thx, D.

chkimes commented 7 years ago

According to that stack trace, it's failing here: https://github.com/ckimes89/graphql-net/blob/master/GraphQL.Parser/Parsing/Parser.fs#L613

The run method there is provided by FParsec, which is what we use to build a parser for the GraphQL library. Do you have the libraries FParsec and FParsecCS included in your GAC?

MakaBuka commented 7 years ago

yeah - https://www.screencast.com/t/Tjgeroixn Honestly, I'm not familiar with F#, so, I can't figure out what the reason of issue is. Thx, D.

chkimes commented 7 years ago

Hmm, I'm fumbling here as well since assembly resolution errors are notoriously hard to debug. The only thing I can think of is that the referenced FParsec version is 1.0.2, and the screenshot there says the version is 1.0.0.0. I'm not sure if that's enough to cause a MissingMethodException though.

MakaBuka commented 7 years ago

Hi ckimes89,

I don't know why, but the latest version of GraphQL.NET lib doesn't work (not even under sharepoint) and throw next exception:

"System.TypeInitializationException: The type initializer for '<StartupCode$GraphQL-Parser>.$GraphQL.Parser.Parser' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'FParsec-Pipes, Version=0.1.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)\u000d\u000a at <StartupCode$GraphQL-Parser>.$GraphQL.Parser.Parser..cctor()\u000d\u000a --- End of inner exception stack trace ---\u000d\u000a at GraphQL.Parser.Parser.parseDocument(String source)\u000d\u000a at GraphQL.Parser.GraphQLDocument1.Parse(ISchema1 schema, String source)\u000d\u000a at GraphQL.Net.GraphQL1.ExecuteQuery(String queryStr, TContext queryContext)\u000d\u000a at GraphQL.Net.GraphQL1.ExecuteQuery(String queryStr)\u000d\u000a

So, I decided to downgrade this lib to version 0.3.1 and it works properly. As far as u remember - we should use strongly-named assembly to use it under sharepoint.

Could you check out the latest update of GraphQL lib?

Thx, D.

MakaBuka commented 7 years ago

Hi ckimes89,

It's unbelievable but it works! So, steps what I did: 1) clone FParsec-Pipes rpject and downgrade it to Version=0.1.1.0 2) signed this lib. 3) in project GraphQL.Parser replace ref FParsec-Pipes to signed FParsec-Pipes 4) deployed these libs to my WCF service.

So, could you sign FParsec-Pipes and deploy it to nuget package?

Thx, D.

chkimes commented 7 years ago

Awesome, glad to hear it works! I don't own the FParsec-Pipes library, but I created an issue on their repo to sign the assemblies. I'll push a new NuGet package when that happens.

progsherief commented 7 years ago

when i try step 3:- in project GraphQL.Parser replace ref FParsec-Pipes to signed FParsec-Pipes , I have this error: Severity Code Description Project File Line Suppression State Error--------->No overloads match for method 'op_PercentBangBangTwiddleTwiddlePercent'. The available overloads are shown below (or in the Error List window). GraphQL.Parser D:\xx\graphql-net-master\graphql-net-master\GraphQL.Parser\Parsing\Parser.fs 204 at this line %% 'u' -- +.(4, hex) -%> unicode -------on Parser.fs file

--Knowing that i am try using GraphQL at .net throw this error: could not load assembly : FParsec-Pipes version 0.1.1.0, Astrongly- named assembly required

chkimes commented 7 years ago

Hi All,

I have released version 0.3.3 on NuGet. The version is strongly named, references the newest FParsec-Pipes which is also strongly named, and fixes the compilation error in the parser caused by a breaking change in FParsec-Pipes. You should now be able to install GraphQL.Net through NuGet for SharePoint.