Graphql server URI

I am looking at using the apollo Graphql client to consume the Ghost content API. I understand that Ghost API consists of various end points (posts, tags, pages etc…) but cant see an end point for the Graphql server?

Is there a graphql server implementation in Ghost? If not, are you expecting the apollo client to consume rest APIs? If so, would you be so kind to share some sample code on how to integrate Ghost with apollo client. More specifically on the URI and the contentAPIKey connection.

Ghost’s APIs are all REST-based. There is no GraphQL API.

Apollo server is designed to consume REST API’s and convert them for use with GraphQL clients - if you follow their tutorial they give a clear example for how to setup a server that does this. The client part of the tutorial is not quite so good but the server side part is pretty detailed.

If you get stuck this question would be IMO much better placed in the Apollo community as you’re asking how to make Apollo work, rather than anything that’s specific to Ghost or the Ghost community.

1 Like

Thanks for your swift reply @Hannah and confirming that there is no Graphql server in Ghost. From your response, I understand that I should create my own Graphql server to consume the Ghost content API. I see that this has been done with Gatsby. I shall look there for sample code.

Out of interest, are they any plans to support Graphql queries out of the box? Something similar to Keystone CMS?

No plans to add a GraphQL API at present, no.

Gatsby isn’t going to help you create a GraphQL server, Gatsby is a static side generator. Again creating a GraphQL server to consume REST APIs is exactly what Apollo server is for.

@Hannah I didnt say that I was going to use Gatsby as a Graphql server. :slightly_smiling_face: What I meant is there is a package developed by Ghost here GitHub - TryGhost/gatsby-source-ghost: Source plugin for pulling data into Gatsby.js from the Ghost Public API.. This integrates Ghost content API with Gatsby which uses graphql. Its a good starting point.

Also as you keep re-iterating that a graphql server is meant for consuming REST API, yes I agree. However a grapqhql server can have many other datasources, mongoDb, postgres etc…

To help others who are interested in implemented a graphql solution with apollo client for ghost, here is very simplistic/high level architecture:
UI WITH APOLLO CLIENT → CUSTOM GRAPHQL SERVER PROXY TO GHOST API → GHOST API → GHOST DATABASE

My observation is that implementing a graphql solution for Ghost is pointless. In fact it could result in a performance penalty compared with using the Ghost content API directly.

I would like to benefit from the goodness of graphql (get exactly what I need from server) without having to proxy through my own graphql server to get content. As in

UI WITH APOLLO CLIENT → CMS WITH GRAPHQL API → DATASOURCE (MONGODB etc…)

I think Ghost has many great features and is gaining maturity but its not for me. Thanks again for your help @Hannah

I created a project that provides an Apollo GraphQL server for Ghost. It supports querying of all Ghost resources from the Content API. I opened a thread for reviews here.