Question: how to call type.AddListField with parameters
fabiodr opened this issue · comments
Is it possible to define a type field with parameters, like with schema? I'm not getting the syntax right.
Someting like the example below, but for GraphQLTypeBuilder:
GraphQLSchema<EfContext> schema;
schema.AddListField("accountsByGuid", new { guid = Guid.Empty }, (db, args) => db.Accounts.AsQueryable().Where(a => a.SomeGuid == args.guid));
Thanks in advance
Hi Fabio,
Well this is embarrassing. I believe at one point we had that overload, but I may have removed it during an overzealous refactoring. I can work on getting it added back in.
Good to know! then it must be somewhere in git history :)
Fast one.. thanks!! =)
Just another question: can i use GraphiQl client with this solution?
This should be available on NuGet now. The usage looks like:
typeBuilder.AddListField("someName", new { argField = 0 },
(db, args, entity) => entity.OtherThings.Where(t => t.Field == args.argField));
Note that the lambda has 3 arguments, first for your context, second for your args, and third for the entity that the field is being referenced from. This is the same for the AddField
overload.
I'm not sure about GraphiQL, I haven't played with it yet. It should just use GraphQL introspection to discover what is available in the schema and we have introspection implemented, so in theory it will work. In practice, introspection hasn't been thoroughly exercised so I can't predict how well it will work.
That said, you could give it a try and let me know what happens.
Great, thanks for the usage sample.
About GraphiQl, for sure, i'll try this out and let you know.
Closing this issue since the new overload is available on NuGet. If something comes up with GraphiQL, let me know in another issue. Thanks!