Skip to content
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

upgradation of api from 3.1 to 6.0 #3731

Open
himanij949 opened this issue Oct 13, 2023 · 45 comments
Open

upgradation of api from 3.1 to 6.0 #3731

himanij949 opened this issue Oct 13, 2023 · 45 comments

Comments

@himanij949
Copy link

himanij949 commented Oct 13, 2023

Hi,while upgrading the api we are facing issue with DocumentExecutor on below line

await documentexecuter.ExecuteAsync(options).ConfigureAwait(false);

we are getting this values but after upgrading the documentexecutor variable is returning null,
and i am getting some more errors

System.InvalidOperationException: IGraphQLTextSerializer not set in DI container. Add a IGraphQLTextSerializer implementation, for example GraphQL System TextJson.GraphQLSerializer or
GraphQL.NewtonsoftJson.GraphQLSerializer. For more information, see: https://github.com/graphql- dotnet/graphql-dotnet/blob/master/README.md.
at GraphQLDI.GraphQLBuilderBase.<>c.b_0_101ServiceProvider) in //src/GraphQL/DI/GraphQLBuilderBase.cs:line 36 at
Microsoft.Extensions.Dependencylnjection.ServiceLookup.CallSiteRuntimeResolver. VisitDisposeCache(ServiceCallSi te transientCallSite, RuntimeResolverContext context)at Microsoft.Extensions. Dependencyinjection.ServiceLookup.CallSiteVisitor 2 VisitCallSite(ServiceCallSite callSite,TArgument argument)
at Microsoft.Extensions.Dependencyinjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSiteSite. Service ProviderEngineScope scope)
at Microsoft.Extensions.Dependencyinjection.ServiceLookup.DynamicServiceProviderEngine.
<>c_DisplayClass2_0.b_0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType. ServiceProviderEngineScope serviceProviderEngineScope)at
Microsoft.Extensions. DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(ServiceProvider provider. Type service Type)at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T]
(IServiceProvider provider) at GraphQL Server. Transports.AspNetCore.GraphQLHttpMiddleware`1.InvokeAsync(HttpContext context) in PDQS\Graph_QL\src\DUSGraphQLServer Transports.AspNetCore\GraphQLHttpMiddleware.cs:line 77

Argument jobinput' has invalid value. In field 'dateRange': [In field 'startDate: [Expected type 'DateTime', found " 2023-09-27.] In field 'endDate': [Expected type 'DateTime', found "2023-09- 27"]] In field 'scheduleType': [Expected type 'ScheduleType', found Adhoc.] In field 'dataSource: [Expected type DataSourceType', found all.] In field 'outputFormatType': [Expected type 'OutputFormatType", found csv.]"

please help me to resolve those errors.

@Shane32
Copy link
Member

Shane32 commented Oct 13, 2023

Can you post the exact nuget GraphQL packages and version numbers you were using before and what ones you are trying to use now?

@himanij949
Copy link
Author

Before upgradation we are using this packages
image

during upgradation we are using this
image

@Shane32
Copy link
Member

Shane32 commented Oct 13, 2023

Ok, makes sense. One question: In your 'before' list I do not see GraphQL.Authorization. Are you adding authorization? If so, I suggest using the authorization library included within GraphQL.Server.All.

@Shane32
Copy link
Member

Shane32 commented Oct 13, 2023

I can help you with the migration. But first, have you read through the migration documents for each version located here:

@himanij949
Copy link
Author

himanij949 commented Oct 14, 2023

my main project having dependency of two assemblies,
Before upgrading 1st assembly having dll,s
image
after upgrading that assembly version,
image

Before upgradation of second assembly
image

after upgrading the dependent assembly
image

@himanij949
Copy link
Author

yes we have gone through with this upgrade documentation and following it.

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

It looks like you’re upgrading from .NET Core 2.2 to .NET Core 7.0 at the same time - is that correct? Or is this a .NET Framework project?

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

If you’re still getting the error regarding “IGraphQLTextSerializer not set in DI container” then we should review how it’s wired up in your startup.cs / program.cs files. Can you provide the relevant code?

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

Once you have basic “hello world” requests going again then we can fix the date. Probably the date error is due to a field resolver returning a date string for a date graph type instead of returning the date itself. The current version of GraphQL is much more strict about being sure that .NET code returns .NET types, having the scalar convert it to a string when needed. Also on the input side, Newtonsoft by default parses dates, so we need to be sure the date parsing is disabled so the scalar can do this job. So that could be an issue also.

@himanij949
Copy link
Author

my main project is in .net core 3.1 and one dependent assembly is in 3.1 also,second one using .net standard 2.0 and we are migrating to 6.0.

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

my main project is in .net core 3.1 and one dependent assembly is in 3.1 also,second one using .net standard 2.0 and we are migrating to 6.0.

Ok that’s no problem

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

The second problem will be due to the GraphQL response not being serialized by the GraphQL serializer implementation. Can you provide the code that the error stops on?

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

As for the identity client error, I’m not very familiar with that library, but if you post the code that’s causing the issue I could let you know if I have any ideas.

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

your startup looks pretty good. you should be able to remove these lines:

    services.AddSingleton<IServiceProvider>(s => new FuncServiceProvider(s.GetRequiredService));
    services.AddSingleton<IDocumentExecuter, DocumentExecuter>();
    //services.AddSingleton<IDocumentWriter, DocumentWriter>();
    services.AddSingleton<IGraphQLSerializer, GraphQLSerializer>();
    services.AddSingleton<ISchema, DUSSchema>();

and then change this line and add another:

//remove:
    //options.AddAutoSchema<Query>();
//add:
    options.AddSchema<DUSSchema>();
    options.AddNewtonsoftJson(); // or options.AddSystemTextJson();

Is GraphQLAuthMiddleware one of your classes? I don't recognize it from any current versions of GraphQL.NET code.

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

Can you provide the stack trace for the error you're receiving? Also the definition of the jobInput argument and the code that defines the startDate and endDate fields.

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

I'm also having difficulty finding what app.UseGraphQLAuth(); does. Is this also part of your code?

@himanij949
Copy link
Author

When i am trying to resolve this error i have added this lines for removig this error can you confirm is it correct
Argument 'jobInput' has invalid value. In field 'dateRange': [In field 'startDate': [Expected type 'DateTime']
image

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

It is unlikely that will help. options.AddNewtonsoftJson already sets those options by default.

https://github.com/graphql-dotnet/graphql-dotnet/blob/master/src/GraphQL.NewtonsoftJson/JsonSerializerSettings.cs

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

Can you provide the stack trace for the error you're receiving? Also the definition of the jobInput argument and the code that defines the startDate and endDate fields.

I'll need this to continue analysis.

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

My comment about date parsing is really only applicable when you're using NewtonsoftJson directly, such as through custom middleware or a MVC endpoint. But in your case you are using the ASP.Net Core middleware within GraphQL.NET Server which should have all the default options set up correctly.

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

I'd also suggest switching to the SystemTextJson serializer, which is natively async, but it should work identical either way.

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

Are there graph types defined for these fields? Or using AutoRegisteringInputObjectGraphType?

@himanij949
Copy link
Author

yes we have graphtype defined.

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

are they using DateTimeGraphType or DateGraphType ?

@himanij949
Copy link
Author

DateTimeGraphType

@Shane32
Copy link
Member

Shane32 commented Oct 14, 2023

Ok then that's your problem. In GraphQL.NET v4 (?) and newer, DateTimeGraphType requires date/time values in ISO-8601 format such as:

  • 2023-10-14T12:34:56Z or
  • 2023-10-14T12:34:56.789-05:00

It will parse those values and convert them into UTC DateTime instances, and it will reject any other format. To use ISO-8601 date-only format, use the DateGraphType which will serialize and deserialize values in this format:

  • 2023-10-14

See:

You can of course create a custom scalar which will deserialize and serialize DateTime values the way that works best for you.

New to .NET 6 is the DateOnly format, also supported by GraphQL.NET via the DateOnlyGraphType. It also only accepts ISO-8601 date-only formats when serializing or deserializing. Now that SqlClient supports DateOnly, I've converted my own applications to use only DateOnly or DateTimeOffset values throughout, corresponding to the SQL date and datetimeoffset data types, never using DateTime unless necessary.

@himanij949
Copy link
Author

Ok then that's your problem. In GraphQL.NET v4 (?) and newer, DateTimeGraphType requires date/time values in ISO-8601 format such as:

  • 2023-10-14T12:34:56Z or
  • 2023-10-14T12:34:56.789-05:00

It will parse those values and convert them into UTC DateTime instances, and it will reject any other format. To use ISO-8601 date-only format, use the DateGraphType which will serialize and deserialize values in this format:

  • 2023-10-14

See:

You can of course create a custom scalar which will deserialize and serialize DateTime values the way that works best for you.

New to .NET 6 is the DateOnly format, also supported by GraphQL.NET via the DateOnlyGraphType. It also only accepts ISO-8601 date-only formats when serializing or deserializing. Now that SqlClient supports DateOnly, I've converted my own applications to use only DateOnly or DateTimeOffset values throughout, corresponding to the SQL date and datetimeoffset data types, never using DateTime unless necessary.

Thankyou so much for your response and support,issue has been resolved.

@himanij949
Copy link
Author

himanij949 commented Oct 15, 2023

we are getting error in this now,when we are sending in this casetype '"json" it is throwing error,please guide me.
outputFormatType: json
"Argument 'jobInput' has invalid value. In field 'outputFormatType': [Expected type 'OutputFormatType', found json.]",
public enum OutputFormatType
{
JSON = 1,
CSV = 2,
}

@Shane32
Copy link
Member

Shane32 commented Oct 15, 2023

we are getting error in this now,when we are sending in this casetype '"json" it is throwing error,please guide me. outputFormatType: json "Argument 'jobInput' has invalid value. In field 'outputFormatType': [Expected type 'OutputFormatType', found json.]", public enum OutputFormatType { JSON = 1, CSV = 2, }

Enums are case sensitive now, pursuant to the GraphQL specification. Probably a v4 change.

@Shane32
Copy link
Member

Shane32 commented Oct 15, 2023

and we are getting this error if you have any idea to how to resolve image image

issue resolved.

Both issues?

The first issue is because ExecutionResult.Data contains a RootExecutionNode now instead of a dictionary. The second issue is because you have a Field / Resolve instead of FieldAsync / ResolveAsync.

@himanij949
Copy link
Author

all issue has been resolved,thankyou so much for your help and support.

@himanij949
Copy link
Author

one issue is pending,once that will resolve i will close this ticket.

@himanij949
Copy link
Author

Hi,Do you have any idea how to convert this input parameter enum case sensitive to case insensitive,so it will accept all cases.

we are getting error in this now,when we are sending in this casetype '"json" it is throwing error,please guide me. outputFormatType: json "Argument 'jobInput' has invalid value. In field 'outputFormatType': [Expected type 'OutputFormatType', found json.]", public enum OutputFormatType { JSON = 1, CSV = 2, }

Enums are case sensitive now, pursuant to the GraphQL specification. Probably a v4 change.

@Shane32
Copy link
Member

Shane32 commented Oct 17, 2023

Add this class:

    public class CaseInsensitiveEnumGraphType<T> : EnumerationGraphType<T>
        where T : Enum
    {
        /// <inheritdoc/>
        public override object? ParseLiteral(GraphQLValue value) => value switch {
            GraphQLEnumValue enumValue => Values.FindByName(enumValue.Name.ToString().ToUpperInvariant())?.Value ?? ThrowLiteralConversionError(value),
            GraphQLNullValue _ => null,
            _ => ThrowLiteralConversionError(value)
        };

        /// <inheritdoc/>
        public override bool CanParseLiteral(GraphQLValue value) => value switch {
            GraphQLEnumValue enumValue => Values.FindByName(enumValue.Name.ToString().ToUpperInvariant()) != null,
            GraphQLNullValue _ => true,
            _ => false
        };

        /// <inheritdoc/>
        public override object? ParseValue(object? value) => value switch {
            string s => Values.FindByName(s.ToUpperInvariant())?.Value ?? ThrowValueConversionError(value),
            null => null,
            _ => ThrowValueConversionError(value)
        };

        /// <inheritdoc/>
        public override bool CanParseValue(object? value) => value switch {
            string s => Values.FindByName(s.ToUpperInvariant()) != null,
            null => true,
            _ => false
        };
    }

Then add this in your startup:

        // make all enums case insensitive
        services.AddTransient(typeof(EnumerationGraphType<>), typeof(CaseInsensitiveEnumGraphType<>));

It should work across your entire codebase with no other code changes, so long as you typically just use EnumerationGraphType<T> and do not manually define your enum graph types. And as long as you don't set ResolvedType in your graphs. So then SchemaTypes during schema initialization will try to instantiate an instance of EnumerationGraphType<T> from DI for each enum, which will then return an instance of CaseInsensitiveEnumGraphType<T>.

@himanij949
Copy link
Author

I have manually define enum graph type and set ResolvedType in my graphs,can you provide any other solution,because i cant change this in my api.

@Shane32
Copy link
Member

Shane32 commented Oct 17, 2023

If you provide a sample of an enumeration graph type I can demonstrate the changes required

@himanij949
Copy link
Author

image image

@Shane32
Copy link
Member

Shane32 commented Oct 17, 2023

Just change the base type of your enumeration graph types to the one I posted. Should work fine.

@himanij949
Copy link
Author

Thankyou so much @Shane32,it is working fine.

@himanij949
Copy link
Author

himanij949 commented Oct 30, 2023

Ok then that's your problem. In GraphQL.NET v4 (?) and newer, DateTimeGraphType requires date/time values in ISO-8601 format such as:

  • 2023-10-14T12:34:56Z or
  • 2023-10-14T12:34:56.789-05:00

It will parse those values and convert them into UTC DateTime instances, and it will reject any other format. To use ISO-8601 date-only format, use the DateGraphType which will serialize and deserialize values in this format:

  • 2023-10-14

See:

You can of course create a custom scalar which will deserialize and serialize DateTime values the way that works best for you.
New to .NET 6 is the DateOnly format, also supported by GraphQL.NET via the DateOnlyGraphType. It also only accepts ISO-8601 date-only formats when serializing or deserializing. Now that SqlClient supports DateOnly, I've converted my own applications to use only DateOnly or DateTimeOffset values throughout, corresponding to the SQL date and datetimeoffset data types, never using DateTime unless necessary.

=
hey,i am getting one error from this i changed from datetime' to 'dateonly' but in some where in our some Api call we are getting this error errors":[{"message":"Argument 'dateRange' has invalid value. In field 'startDate: [Expected type 'DateTime', found "10/1/2023 12:00:00 AM] In field 'endDate': [Expected type 'DateTime, found "10/16/2023 12:00:00 AM

if you have any solution where it will accept for all date formats,if you help it would be grateful. Thanks

@Shane32
Copy link
Member

Shane32 commented Oct 30, 2023

I would suggest making a custom scalar. You can then customize the date parsing in any way you wish.

I would start by duplicating the source code of DateGraphType or DateOnlyGraphType and modifying it as needed. You can read detailed instructions for custom scalars here:

You will likely need to register the custom scalar with your schema - see this link:

Anything that directly references DateGraphType or DateOnlyGraphType may need to change to reference your new class.

Once complete, your schema will parse date formats based on the code you've written in the custom scalar, and you should have no more trouble.

@Shane32
Copy link
Member

Shane32 commented Oct 30, 2023

Note that this should be pretty easy to do. Let me know if you run into any difficulty.

@Shane32
Copy link
Member

Shane32 commented Dec 31, 2023

Please re-open if you have further issues

@Shane32 Shane32 closed this as completed Dec 31, 2023
@himanij949
Copy link
Author

Hi Shane,we are getting one exception,while we are creating JWT token for a 1st time it is generating in properly format,but after hitting second time,miliseconds are it get trimmed after we are converting else it will not generating the mili second.
datetime

@Shane32
Copy link
Member

Shane32 commented Jan 2, 2024

GraphQL.NET doesn't deal with JWTs directly. If you're using GraphQL.NET Server, well it doesn't either except for within the JWT sample application. What code are you using to generate your JWTs? Not that it should do that, but is the lack of decimals a problem?

@Shane32 Shane32 reopened this Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants