byme8 / ZeroQL

C# GraphQL client with Linq-like syntax
MIT License
273 stars 13 forks source link

Single query with multiple query roots #73

Closed richarddavenport closed 12 months ago

richarddavenport commented 12 months ago

Given this schema:

schema {
  query: Queries
}

type Queries {
  me: User!
  user(id: Int!): User
}

type User {
  id: Int!
  firstName: String!
  lastName: String!
}

The library currently support a query like this:

query { 
  me { id firstName lastName  }
}

Using this type of C# syntax:

var response = await client.Query(o => o.Me(o => new { o.Id, o.FirstName, o.LastName }));

I'm looking for guidance on a query like this:

query { 
  me { id firstName lastName  }
  user(id: 123) { id firstName lastName  }
}
byme8 commented 12 months ago

You can do it like that:

var response = await client.Query(o => new { 
    Me = o.Me(o => new { o.Id, o.FirstName, o.LastName }),
    User = o.User(123, o => new {o.Id, o.FirstName, o.LastName})
});
richarddavenport commented 12 months ago

Thanks @byme8! We can close this issue.