Any working solutions of using Relay/GraphQL with Loopback? I guess a few things I'm considering are how to access the database (since I'm assuming going through the ORM wouldn't be possible) and how to leverage the api generators when using Relay/GraphQL...
I have created this npm library to generate GraphQL schema from loopback models: https://github.com/Tallyb/loopback-graphql
Just for the other people out there, I came across this answer and I was still confused whether I could implement a GraphQL api in Loopback or not. I used Apollo's apollo-server package for Express. Since Loopback is based on Express, calling
app.use('/graphql', bodyParser.json(), graphqlExpress({schema}));
app.use('graphiql', graphiqlExpress({
endpointURL: "/graphql"
}))
works perfectly out of the box. Just follow their tutorials for Express code and it should work. As far as the database stuff goes, it seems like you can use resolvers as the middle layer in place of Loopback's remote methods. For each resolver that points to a piece of data, you can call the contextual app
method to fetch data from your database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With