chkimes / graphql-net

Convert GraphQL to IQueryable
MIT License
891 stars 86 forks source link

Add expression option to use base type. #85

Closed MarianPalkus closed 6 years ago

MarianPalkus commented 7 years ago

I ran into an issue when executing queries against mutation results with Entity Framework when a mutation returns a EF proxy.

Looking at Executor (line 19ff):

public static object Execute
    (GraphQLSchema<TContext> schema, TContext context, GraphQLField field, ExecSelection<Info> query)
{
    var mutReturn = field.RunMutation(context, query.Arguments.Values());

    var queryableFuncExpr = field.GetExpression(query.Arguments.Values(), mutReturn);
    var replaced = (LambdaExpression)ParameterReplacer.Replace(queryableFuncExpr, queryableFuncExpr.Parameters[0], GraphQLSchema<TContext>.DbParam);

    // sniff queryable provider to determine how selector should be built
    var dummyQuery = replaced.Compile().DynamicInvoke(context, null);
    var queryType = dummyQuery.GetType();

In this case the queryType is System.Data.Entity.DynamicProxies, but we are interested in the queryType.BaseType.

This PR adds an expression option to handle this.

MarianPalkus commented 6 years ago

@ckimes89 will you find time to look at this PR or shall i merge it?