Apollo with a restful Express App

Hi,

I have a RESTful ExpressJs website that performs a number of CRUD operations using Sequelize. Data is served up to the user using a template engine. It’s a pretty simple website that is a small part of a larger application.

So that I can use a common data access API, what is the best way to swap Sequelize out for Apollo? Is there some sort of server side only endpoint provided by Apollo that I can call to access the its functionality?

Are there any examples of this and are there any reasons not to do this? As I am new to this, I may not be understanding how this works.

Many thanks

JT

Hi,

You wouldn’t need to swap out Sequelize. Apollo is designed to be integral with any backend technology, so something like Sequelize will work perfectly with it. Check out the Apollo Docs for more detail or the introduction for getting started. Here’s also a repo that based on the tutorial from the Apollo docs.

Regards,
EU

2 Likes

Thanks EU,

What the examples don’t show is how to access the graph server directly without having to make a call over http to the graph server’s end point. Is this possible?

For example, define my GQL on the sever and then simply fire it off to the GQL processor to return a result. All in code with not http call.

The reason I want to do this is because I want the same API for doing everything. Otherwise I will end up with two lots of access code.

I really feel like I am missing something here.

Cheers

JT

:thinking: I’m not too sure but I do know GraphQL is built for a unified API so you should be able to use the same API for doing everything you need to. Ok so are you saying you’d like to query your GraphQL API without make a HTTP request from the client just like the GraphiQL IDE but in code.

@paistipoikka1, your question is unclear. I’m not sure what you’re asking about. The point of your GraphQL server is precisely this: to create an API that can be accessed by a single HTTP endpoint.

What you need to do is look at this project: https://github.com/apollostack/GitHunt-API

Just replace the models that are using knex with your Sequelize. You will have to do some work to make your CRUD operations into GraphQL mutations and queries.

I agree with @vonwao. It seems your idea of GraphQL is skewed and you need to revisit the concepts because you initially mentioned that you wanted to swap out Sequelize for GraphQL.

GraphQL is not a query language for your database it is a query language in a sense of how calling various URL endpoints to a REST API is a query language for retrieving data from your server (again not database specific). But with GraphQL it’s just one URL endpoint that you need to call.

Check out this GraphQL talk by the co-creator himself. He describes the misconceptions well and the purpose of GraphQL.

I think this video explains how to do exactly what you want.

1 Like