Comments (13)
No worries,
For people that have the same issue, I managed to work through it by using graph-QL requests to forward requests to Prisma. It allowed me to simplify the API exposed to the clients, at the cost of poorer performance, as you lose the ability to select fields on the Prisma requests.
It's definitely a workaround, but it works for my use-case. I just return all fields and let yoga filter out the ones I don't care about. When this bug is closed I should be able to just forward the requests.
resolver function
export const Query = {
async postsByUser(parent, args, ctx: Context, info) {
return getPostsByUser(args.userId, ctx)
},
}
export async function getPostsByUser(userId: string, ctx: Context) : Promise<[FeedPost]> {
const selection = fs.readFileSync('postsByUser.graphql', {encoding: "utf8"});
const variables = {author: userId};
let response = await ctx.graphQlClient.request(selection, variables);
return response.user.posts.map((post: Post) => postToContent(post));
}
postsByUser.graphql
query postsByUser($author: ID!) {
user(where: {id: $author}) {
posts (orderBy: updatedAt_DESC) {
id
updatedAt
content {
id
updatedAt
reviews {
id
review
user {
id
....
}
updatedAt
}
posts {
author {
id
....
}
updatedAt
}
userPosts: posts(first: 1, where: {author: {id: $author}}) {
id
}
userSaves: saves(first: 1, where: {user: {id: $author}}) {
id
}
userReviews: reviews(first: 1, where: {user: {id: $author}}) {
id
}
video {
id
....
}
book {
id
....
}
}
}
}
}
(If anyone has good resources on the GraphQLResolveInfo object and how it can be used to map and select fields this would be useful)
from prisma-binding.
Thanks for sharing the workaround, @RoryKelly! 🙌 That's super helpful.
We recently published a blog post with more information on the info
object! 🙂 This example also contains many different uses and patterns for resolvers: https://github.com/graphcool/graphql-server-example
from prisma-binding.
from prisma-binding.
I can confirm that this appears to be fixed for me. Also, @lueurxax's workaround is way better than mine. I didn't understand how custom type resolvers work. Thanks @marktani for the link really cleared up how to define an application schema in front of the one exposed by Prisma.
from prisma-binding.
Which one is the expected result?
from prisma-binding.
I edited my original post to try and provide some clarity. Let me know if I can provide any further information.
from prisma-binding.
Just some more information. If i bypass prisma-binding and use 'graphql-request' to forward requests to prisma, I get the same behaviour. This would suggest ( to me) the the problem is in graphql-yoga.
async feedItems(parent, args, ctx: Context, info) {
const userId = getUserId(ctx);
let response = await ctx.graphQlClient.request(ctx.request.body.query, ctx.request.body.variables);
return response.feedItems;
},
from prisma-binding.
I'm sad, it's stopper for me
from prisma-binding.
@RoryKelly @lueurxax we'll be looking into this! Sorry about the inconvenience!
from prisma-binding.
No worries,
For people that have the same issue, I managed to work through it by using graph-QL requests to forward requests to Prisma. It allowed me to simplify the API exposed to the clients, at the cost of poorer performance, as you lose the ability to select fields on the Prisma requests.
It's definitely a workaround, but it works for my use-case. I just return all fields and let yoga filter out the ones I don't care about. When this bug is closed I should be able to just forward the requests.
This is a bad attempt, because Prisma has only ten threads...
java.util.concurrent.RejectedExecutionException: Task slick.basic.BasicBackend$DatabaseDef$$anon$2@1171acb8 rejected from slick.util.AsyncExecutor$$anon$2$$anon$1@11e0b2dc[Running, pool size = 10, active threads = 10, queued tasks = 1000, completed tasks = 1916]
from prisma-binding.
I found the better way. For query
query feed($authorId: ID!) {
posts {
video {
a: posts(where: {tag: { name: "fun" } }) {
id
}
b: posts(where: {tag: { name: "politics" } }) {
id
}
}
}
}
in resolvers/index.js
module.exports = Object.assign({
Query,
Mutation,
AuthPayload,
}, postsResolver);
post resolver
const postResolver = {
Video: {
posts: async (parent, args, ctx, info) => {
if (args.where.tag.name === 'fun') return parent.a;
else if (args.where.property.name === 'politics') return parent.b;
},
},
}
You can extend this example.
prisma-bidding: renaming -> you: reverse renaming -> graphql-yoga: renaming
from prisma-binding.
Thanks for reporting @RoryKelly & @lueurxax we did a recent fix that seems to have fixed it. It's available in [email protected]
. Can you give it a try? Thanks!
from prisma-binding.
Awesome, glad that cleared things up :) Thanks for confirming, I'm closing this now.
from prisma-binding.
Related Issues (20)
- how to submit many transactions
- Connect Prisma Bindings to mock server
- Calling a query from Yoga to Prisma does nothing. HOT 5
- Case Sensitive Query Adjustments. HOT 2
- Calling multiple prisma requests returns same error to all the request if any one of them gives error.
- forwardTo() without having to specify resolver keys
- Cannot set property 'fragmentReplacements' of undefined HOT 1
- forwardTo with type rename
- how to get the count of records
- Howto define subscription endpoint
- Sub-selecting custom fields HOT 2
- Subscription Implementation with Prisma Binding
- Improve Code Readability
- error when trying to call aggregate function HOT 1
- Aliases still not works correctly
- How to filter `Where null` HOT 1
- Prisma() not recognized as a constructor HOT 1
- Import error on IResolvers from graphql-tools
- The automated release is failing 🚨
- Version of this for graphql-code-generator ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prisma-binding.