-
-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate most GraphService methods and converge on two standard methods #1051
base: master
Are you sure you want to change the base?
Conversation
Should it be also be possible to provide variables via a dictionary? |
Oh yeah, I like that more @clement911! So maybe we change the GraphRequest class to look like this: public class GraphRequest
{
public string Query { get; set; }
public Dictionary<string, object> Variables { get; set; }
// Convenience methods for adding/setting variables?
public GraphRequest AddVariable(string key, object value)
{
Variables.Add(key, value);
return this;
}
public GraphRequest SetVariable(string key, object value)
{
Variables.Set(key, value);
return this;
}
} Then you could just pass in an entire dictionary if you've already got one, use the convenience methods, or access the dictionary object directly. |
I'm not sure that the |
Agreed, I was thinking about that too and it doesn’t sound that useful. I’m going to drop that idea, but I did make the change to switch the Variables type to a dictionary.—Joshua HarmsOn Apr 7, 2024, at 17:19, Clement Gutel ***@***.***> wrote:
I'm not sure that the AddVariable / SetVariable methods really are needed.
The user can simply use the Variables dictionary to manage variables, right?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
2f61904
to
05fa543
Compare
05fa543
to
02ea7b9
Compare
… methods This change deprecates most GraphService.PostAsync and GraphService.SendAsync methods, of which there were at least six total. It introduces two new GraphService.PostAsync methods to replace them all, which standardize the usage of the `GraphRequest` class and serializing all requests to json. Previously, some of the PostAsync/SendAsync methods would serialize the request to json, some wouldn't. Some would send the variables, some wouldn't. Some would let you set your own json wherein you could apply the variables yourself, but then they'd send the `application/graphql` content-type, which made Shopify ignore any variables sent.
02ea7b9
to
5647733
Compare
…dGraphResponse class for deserializing GraphQL responses Changes: - Introduced a new class named `ParsedGraphResponse<T>` to be used for deserializing Shopify's GraphQL responses. It includes two properties: `Data` of type `T` and `UserErrors` of type `ICollection<UserError>`. - Modified the error handling logic in `GraphService` to use the new `ParsedGraphResponse<T>` class. - Refactored all public methods in `GraphService` to use the same internal method for calling the GraphQL API. Tests will be added to ensure the obsoleted methods have not been broken. - Deprecated `GraphService.CheckForErrors<T>`
Type: feature
… JsonSerializerOptions
Planning to use a camel case property name strategy with System.Text.Json instead.
18ca45f
to
8e15fe8
Compare
Remaining tasks:
|
…ing for userErrors
Worried about too much memory usage/potential memory leaks by using JsonElement for unknown, potentially gigantic json values in an exception.
672b04e
to
1b92e9a
Compare
e6492c3
to
4daf9f1
Compare
This change deprecates most GraphService.PostAsync and GraphService.SendAsync methods, of which there were at least six total. It introduces two new GraphService.PostAsync methods to replace them all, which standardize the usage of the
GraphRequest
class and serializing all requests to json.Previously, some of the PostAsync/SendAsync methods would serialize the request to json, some wouldn't. Some would send the variables, some wouldn't. Some would let you set your own json wherein you could apply the variables yourself, but then they'd send the
application/graphql
content-type, which made Shopify ignore any variables sent.That one has personally bit me each time I've tried to use the GraphService recently; it's been difficult to figure out which method should be used on the service when I want to send variables, without looking at the source code for ShopifySharp.
After this change, the new method for sending Graph requests using the GraphService going forward would look like this:
I don't want anyone to lose the ability to control how variables are serialized or deserialized though, so I've added an
IGraphSerializer
interface that can be passed to the GraphService constructor.I'm not 100% sure this is the exact interface I'll use for this, but it's something along the lines of what I'm thinking. Whether we use this interface or do something else for serialization/deserialization in the GraphService, I want it to play nicely with the factory and DI package.