ShopifySharp icon indicating copy to clipboard operation
ShopifySharp copied to clipboard

ShopifySharp.GraphQL missing. (.NET Framework 4.8 project)

Open trint99 opened this issue 1 year ago • 9 comments

My project is mired in .NET Framework 4.8 with no prospect of migrating soon.

I have ShopifySharp 6.22.2 installed.

The code samples from the wiki don't work. I can translate most of them, but the missing library has me stumped.

Image

How do I access the new GraphQL library?

trint99 avatar Mar 18 '25 17:03 trint99

Same with .net core 3.1

D3bo avatar Mar 19 '25 08:03 D3bo

Also looking for this as my integration is .NET Framework. The short answer seems to be that all the classes in the ShopifySharp.GraphQL namespace are only included in the ShopifySharp nuget targeting .NET 6 or higher. This is controlled in the source code here:

Image

@clement911 or @nozzlegear may be able to explain why.

lanthonyneville avatar Mar 20 '25 15:03 lanthonyneville

On further digging the answer to why the classes in the ShopifySharp.GraphQL namespace are not available for .NET Framework is because the code makes heavy use of "default interface members", which are not supported in .NET Framework.

What I am doing is copying the classes I need out of the source code (e.g. Product, ProductOption etc) plus their dependencies (GraphQLObject<T> etc) into my own project, and adapting it to build under .NET Framework (e.g. removing default interface members from interfaces, and adding concrete implementations in the classes to satisfy the interfaces). Then these classes in theory can be used with the GraphService PostAsync method.

lanthonyneville avatar Mar 20 '25 17:03 lanthonyneville

Yes, you've got that correct @lanthonyneville. Unfortunately they're not available in .NET < 6 right now because of the default interfaces. I am actively looking into making them available in .NET Framework/Standard, I just don't have an ETA for it as it may tie into my source generator strategy for #1137.

nozzlegear avatar Mar 20 '25 18:03 nozzlegear

#1143 contains more info about why they don't currently work in .NET Framework right now, but you've summarized it pretty succinctly: the current implementation uses default interface methods and other .NET >= 6 features that just don't work in .NET Framework.

nozzlegear avatar Mar 20 '25 18:03 nozzlegear

Thanks @nozzlegear . For now, I have rewritten my .NET Framework code that used the ProductService and ProductVariantService to instead make direct GraphQL calls to Shopify. It's an ugly fix, but I should have it working soon. I look forward to using your new services once they're finished.

trint99 avatar Mar 20 '25 20:03 trint99

@nozzlegear I'm getting the same issue as @trint99 in my .net 6.0 project despite the #if NET6_0_OR_GREATER directive. Is this expected behavior?

devtest444555 avatar Apr 01 '25 19:04 devtest444555

@devtest444555 Hey! That's not expected behavior, it should work in a .NET 6 project. Are you on the latest version of ShopifySharp? And if possible, can you try upgrading to .NET 8? I believe .NET 6 is no longer supported by Microsoft, and the upgrade to .NET 8 is pretty painless if I remember correctly.

nozzlegear avatar Apr 01 '25 19:04 nozzlegear

@nozzlegear Hi! I'm currently using the latest (6.22.2), and interestingly, I just found an issue experiencing that same strange behavior: Here

Thanks, I think you're right. Upgrading to .NET 8.0 would be the way to go.

And sorry, I'm rather new to GraphQL, but how did you generate the GraphQLSchema.generated.cs ? Can the method you used to do that be used for other GraphQL APIs?

devtest444555 avatar Apr 01 '25 20:04 devtest444555