CannerCMS/cannercms

How to connect exist graphQL endpoint?

hank9653 opened this issue · 4 comments

Hi, I want connect exist graphQL endpoint, but there seems to be no relevant information in the document.
Please what do I can find it in somewhere?

Hi, @hank9653, thanks for the question. Actually, the implementation isn't written in our document, so I just note it below.

NOTICE: your graphQL endpoint should follow https://github.com/opencrud/opencrud

You can simply new a GraphqlClient instance and put it into your <root> tag. If you're using CLI to serve or deploy, you don't have to install canner-graphql-interface manually.

canner.schema.js

import CannerScript from 'canner-script';
import {GraphqlClient} from 'canner-graphql-interface';

const graphqlClient = new GraphqlClient({
  uri: "http://localhost:4000/graphql",
  credentials: "same-origin"
});

export default () => (
  <root graphqlClient={graphqlClient}>
    {/* ... your schema */}
  </root>
)

GraphqlClient constructor arguments

{
    uri: string,
    headers?: any,
    fetch?: any,
    includeExtensions?: boolean,
    credentials?: string,
    fetchOptions?: any,
    useGETForQueries?: boolean
}

Any further questions please let us know, thanks!

It's work, I can get data from the graphQL endpoint, thank you for help.

hi @abz53378 I have the same problem, but this solution did not work for me, I have problems with the CORS, I have enabled them and I continue to generate the same problem ... if you have any example where you can look at all the configuration and development of a project in react , I would like very much ...

HI @charlitoro, sorry about the late reply, to solve the CORS problem, you have to configure your server instead of changing anything about CannerCMS, here is a great explanation of CORS, an article about CORS in express, and in our project, we use @koa/cors. Hope these help!