Graph QL Syntax Highlighting
While configuring my Visual Studio to handle syntax highlighting for GraphQL, i ran into issues with Shopify Sharps GraphRequest class. After doing some more digging, i found that other libraries had the same issue, they had solved it with a decorated constructor parameter. I tested another library (see image) and the behavior is consistent with ShopifySharps behavior when not using the constructor parameter. Had not seen much activity regarding the syntax highlighting, this just serves as a heads up.
Thanks for all the hard work!
@mcash95 Hey, thanks for pointing this out! This has been a tricky one for me to track down, made even trickier by the fact that I don't have a Windows machine myself to debug the problem. I'll need to figure out the best way to do this without introducing breaking changes (only concern is what should happen when the constructor passes a query and the query property is set at the same time), but this should be doable!
I can imagine! For reference here is the link to the repo for the package. https://github.com/graphql-dotnet/graphql-client
Thanks again for the awesome work!
@mcash95 Any chance you could let us know how you got the syntax highlighting to work in Visual Studio? Like which extensions you used etc?
Yes absolutely.
Extensions: GraphQLTools by Code Architects Research (https://marketplace.visualstudio.com/items?itemName=codearchitects-research.GraphQLTools)
Packages: Microsoft's GraphQL-Client package.
Reproduction Steps: In order to make Syntax highlighting happen with the GraphQL client i generated a new GraphQLRequest() passing in the Query string as a parameter to the constructor. ex starts on line 79 of my original post. I was unable to make the same situation happen using the ShopifySharp Library. I tried manually defining the query in a different request (same library) staring on line 48 of my original post, and found that it exhibited the same behavior as ShopifySharp.
@nozzlegear (as stated above) has been working with this issue in ShopifySharp for a while, seems like a general issue across multiple libraries to get syntax highlighting to work as intended. Hopefully that helps you out @kareldonk
@mcash95 Thanks for the info, I had tried that extension but as you mentioned, I was unable to get it working with ShopifySharp and was not sure if this was a problem with the extension or with ShopifySharp. Since I also saw that the extension was not being maintained frequently, I gave up on it.
@mcash95 is just showing a way to make it work in a sample project. That would be the same has changing the GraphRequest class in ShopifySharp to also add these constructors:
public GraphRequest() { }
public GraphRequest([StringSyntax("GraphQL")] string query, object? variables = null)
{
Query = query;
if (variables is IDictionary<string, object> dict)
{
Variables = dict;
}
else if (variables is not null)
{
Variables = variables.ToDictionary();
}
}
@kareldonk, you would have to change the ShopifySharp code to work.
With this modifications you could have intellisense when creating an GraphRequest like this: