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
Nullable reference types not detected in mutation parameters #204
Comments
Pretty sure this is an issue in ArgType.FromParameter. It's passing through prop.Member to MakeArgType which is the parent method instead of the parameter itself. Probably need to switch from using MemberInfo to ICustomAttributeProvider to achieve this. I thought I did that in one of the validation branches, but maybe it never made it. |
Thanks for the test. I'm doing a fix for this now. Also found an issue where |
@lukemurray Would this also fix an issue that I'm running into where nullable collections seem to not be recognized as nullable? #nullable enable
public class User {
public ICollection<Role>? Roles { get; set; } = null;
}
public static void ConfigureSchema(SchemaProvider<...> schema)
schema.AddType<User>("user", null).AddAllFields();
} query:
error: {"errors":[{"message":"Field 'users' - Value cannot be null. (Parameter 'source')"}]} It looks like Entity GraphQL is expecting the If I should open a separate issue for this, just let me know, but I thought it might be related 🙂 |
This is actually hitting an error in the built expression. Likely |
@lukemurray Thanks 🙂 Agreed that it's hitting an error in the built expression. I think the expression in this instance is built by EntityGraphQL, though. Here's a more full snippet: #nullable enable
public class UserDbContext : DbContext {
public DbSet<UserWrapper> UserWrappers { get; set; }
}
public class UserWrapper {
public string Json { get; set; }
}
public class User {
public ICollection<Role>? Roles { get; set; } = null;
}
services.AddGraphQLSchema<UserDbContext>(options =>
{
options.ConfigureSchema = ConfigureSchema;
});
public static void ConfigureSchema(SchemaProvider<UserDbContext> demoSchema)
{
demoSchema.AddType<User>("user", null).AddAllFields();
// Add custom root fields
demoSchema.UpdateQuery(queryType =>
{
queryType.ReplaceField(
"users",
new
{
...
},
(db, args) => db.UserWrappers.Select(userWrapper => JsonConvert.DeserializeObject<User>(userWrapper.Json)).ToList(),
"List of users"
);
});
} |
Yes, I meant an expression that EntityGraphQL built. Like any code If executing against EF we can get away with it as the expression is translated by EF to SQL so the null property is not actually hit. If the data is not EF data context and there is a E.g. EntityGraphQL builds something closer to this users == null ? null : users.Select(u => u.Roles == null ? null : u.Roles.Select(r => new { id = r.Id })) And typing that out I realise it is likely the inner check failing. |
Can I ask what |
@lukemurray (Sorry, I pretty heavily edited my previous post after I posted it, so if you got an email with my reply, it probably has the old example in it) public class UserDbContext : DbContext {
public DbSet<UserWrapper> UserWrappers { get; set; }
}
public class UserWrapper {
public string Json { get; set; }
} |
I'm off of work for today. Will check in again tomorrow, God willing 🙂 |
Whoops I did miss that. Thanks |
@lukemurray It looks like this bug probably isn't related to this issue, so I've split it off into a separate bug report: #221 @breyed Sorry for the noise! 🙂 |
If a mutation uses separate parameters (vs. a parameters object), any of the parameters that are of a reference type and are marked as nullable still show up as non-nullable in the GraphQL.
For example, in a mutation:
Should output the GraphQL:
Currently, it outputs:
EntityGraphQL should inspect the nullability:
The text was updated successfully, but these errors were encountered: