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

IQueryable Select statements #5

Closed
flieks opened this issue Jul 29, 2018 · 18 comments
Closed

IQueryable Select statements #5

flieks opened this issue Jul 29, 2018 · 18 comments

Comments

@flieks
Copy link

flieks commented Jul 29, 2018

Hi Simon,

Does it only select the fields from IQueryable like Dapper ? Dapper seems alot of coding for each resolver so it would be nice not to have to implement Dapper.

@SimonCropp
Copy link
Owner

Navigation properties are selectively included.

for non-navigation properties you can explicitly select what properties to include

        AddQueryField<EmployeeGraph, Employee>(
            name: "employees",
            resolve: context =>
            {
                var dataContext = (MyDataContext) context.UserContext;
                return dataContext.Employees
                    .Select(x => new Employee {FirstName = x.FirstName});
            });

Ideally in the future the non-navigation properties would also be selectively included based on the requested fields on the incoming graph

@flieks
Copy link
Author

flieks commented Jul 30, 2018

super nice for navigation properties (AddNavigationField)
Why is it hard to extend this to the root query (AddQueryField) ?

@SimonCropp
Copy link
Owner

Why is it hard to extend this to the root query (AddQueryField) ?

because this

.Select(x => new Employee {FirstName = x.FirstName});

needs to be dynamically constructed. have a look here for the type of code that needs to be written https://github.com/SimonCropp/GraphQL.EntityFramework/blob/master/GraphQL.EntityFramework/Where/ExpressionBuilder.cs

@flieks
Copy link
Author

flieks commented Aug 7, 2018

@SimonCropp i have a navigationField on Customer :

AddNavigationField<AddressGraph, Address>(
                name: "address",
                resolve: context => context.Source.Address);

And i still see all the Address fields in the sql query, although i only want Id in the request query

@SimonCropp
Copy link
Owner

@flieks happy to accept a PR that fixes that

@flieks
Copy link
Author

flieks commented Aug 9, 2018

@SimonCropp It's possible for Scalar to know which fields to Select on the DBSet so we are interested in implementing this.
But what what about resolvers that want to use data from a Child (navigation) object and then return a StringGraphType for example? Or combine multiple tables to return something.
Should we implement an attribute on the Field<> to indicate which types to Include because the desired include isn't applied now?
And we could also give property names to the same attribute indicating which fields of that type we need for Select()

What do you suggest?

@SimonCropp
Copy link
Owner

But what what about resolvers that want to use data from a Child (navigation) object and then return a StringGraphType for example? Or combine multiple tables to return something.

do you currently have that use case? if not i would ignore it for now

@flieks
Copy link
Author

flieks commented Aug 10, 2018

@SimonCropp yes we have that for many use cases ;).

For example a simple one:
return Quotes.Where(q => q.WonQuote).Sum(q => q.Price)
That should only fetch WonDeal & Price fields of the include
Or even more ideally would do the Where & Sum inside the Linq to Sql Query.

More thoughts:
So now only the main Query have to return DBSets where the subGraph's resolvers have already the executed data which means applying sum & where.
Maybe there's a possibility to return some kind of Expression Type so it can be catched and included in the initial main DBSet linq query.
Do you think it's possible ?

@SimonCropp
Copy link
Owner

Yep i think its possible

@flieks
Copy link
Author

flieks commented Aug 27, 2018

Interesting, i will check it in a week when i have some time

@SimonCropp
Copy link
Owner

Will close this for now. Happy to reopen if someone want to work on it

@sebitsi
Copy link

sebitsi commented Nov 11, 2019

Hi @SimonCropp

Are select (projections) implemented already ?

Will query

query {
  data  {
    id,
    name
  }
}

execute as

Select id, name from data

without all other fields in data table ?

Regards.

@SimonCropp
Copy link
Owner

@sebitsi yes but not as defined in the description above

@sebitsi
Copy link

sebitsi commented Nov 11, 2019

@SimonCropp Thanks for your response.

What do you mean by

yes but not as defined in the description above

Can you please explain more or point me to documentation.

If yes, how it works and what i have to do ?

Regards.

@SimonCropp
Copy link
Owner

@sebitsi you can read about defining graphs here https://github.com/SimonCropp/GraphQL.EntityFramework/blob/master/doco/defining-graphs.md and there is a runnable sample here https://github.com/SimonCropp/GraphQL.EntityFramework/tree/master/src/SampleWeb

BTW if you intending on using the project you should note that it is required that you become a backer https://github.com/SimonCropp/GraphQL.EntityFramework#community-backed

@sebitsi
Copy link

sebitsi commented Nov 12, 2019

Hi @SimonCropp.

  1. I read all contents in links you provide.
    There is no answere how library handles LINQ select on subFields.
    I think library cannot handle scenario as i wrote.
    Please tell how if this is not correct.

  2. AddQueryfield is not working as expected.
    From my code:

public CountryGraph(IEfGraphQLService<CommonDbContext> graphQlService) : base(graphQlService)
        {
            Field(x => x.Id);
            Field(x => x.Name);
            Field(x => x.Code);
            AddQueryField(
                name: "postoffices",
                resolve: context => context.DbContext.Posts.Where(p => p.CountryID == context.Source.Id)
                ) ; 
        }

This config returns data, but there is n + 1 query generated in sql.
One for all countries and n for each postofice:

Select * From Country
Select * From PostOffice Where CountryID = 1
Select * From PostOffice Where CountryID = 2
Select * From PostOffice Where CountryID = 3
etc

Is there an error in my configuration or library cannot handle it.
Please advice.

  1. I will become baker if i decide to use library, Before that i need to know what library can handle and what not.

  2. Do you have some roadmap about features i noticed not working ?

@SimonCropp
Copy link
Owner

sorry. in the form you want it is not supported. no there is no current plan to add that

@sebitsi
Copy link

sebitsi commented Nov 12, 2019

I'm sorry to hear that,

This library has potential.
But without this features and no roadmap i'm affraid cannot choose it for our project.

Thanks for your time.

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

3 participants