question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GraphQL Query string to LINQ Expression

See original GitHub issue

Hi,

This library looks awesome. Apologies in advance if I’ve missed something here. I’ve spent some time looking through the examples on the front page but wasn’t sure how to do this. What I’m looking for is a way to retrieve a LINQ Expression from a GraphQL string query. This would be totally decoupled from EF or even IQueryable.

The delegate would look exactly like this:

delegate Expression GetExpression(string graphQl);

Or potentially this with generics:

delegate Expression<Func<T, bool>> GetExpression<T>(string graphQl);

Is there a straight forward way to implement this delegate with this library?

Christian

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
lukemurraycommented, Jul 24, 2020

hey @MelbourneDeveloper , just looking at this now.

First you do not need to use DbContext you could build a schema from scratch from object type of a custom type like it looks like you have done. This library just builds LINQ expressions against an object structure. If that happens to be a DbContext then you get those benefits.

So you are building a schema from PeopleDbContext can you post that too?

When you compile person.where(name = ""{name}"") against PeopleDbContext it will look for a property/field called person.

Also person.where(name = ""{name}"") is not valid GraphQL, but you are using EntityQueryCompiler which allows this so that’s good, just wanted to spell that out though.

EntityQueryCompiler by itself is, well, less tested.

You should be able to take the compiledQueryResult.LambdaExpression which should be an expression like (Person p) => p.Where(t => t.Name == "...")

Note that perhaps you mean people.where()? But that depends on how you defined the schema or the PeopleDbContext class.

If you can provide a sample project I’d happily have a quick look.

0reactions
lukemurraycommented, Sep 17, 2020

sure thing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL Query string to LINQ Expression · Issue #59
What I'm looking for is a way to retrieve a LINQ Expression from a GraphQL string query. This would be totally decoupled from...
Read more >
Mapping GraphQL query to Select() linq to sql
The best strategy here is using Select() to specific properties we need to fetch. But I have no idea how to build the...
Read more >
Introducing GraphQLinq - Strongly Typed GraphQL ...
To view the generated GraphQL query, call ToString on the LINQ query itself. You will get the GraphQL query together with the variables...
Read more >
Library to compile GraphQL to LINQ expressions (EF ...
I thought I'd share a library I have been working on and use in production for some time. Ultimately I'd love some feedback....
Read more >
C# Linq for GraphQL queries
Putting it all together, I got a mechanism that allows using Expressions to form the correct GraphQL string for a subsequent request to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found