I am using Prismic for website content serving purpose and management. Now I am trying to use for my mobile application as well. I am using apollo apollo-link library to connect to Prismic Graphql server. As a start, when I tried to from local system, i am started having this below CORS issue.
Following up in case others run into this, after re-reading the docs I see that Prismic only supports GET vs POST, which is the standard most libraries use. I’ve been able to get things working with the custom prismic Apollo link.
Here’s the snippet that works:
import { PrismicLink } from “apollo-link-prismic”;
import { InMemoryCache, IntrospectionFragmentMatcher } from “apollo-cache-inmemory”;
import ApolloClient from “apollo-client”;
import gql from “graphql-tag”;
const client = new ApolloClient({
link: PrismicLink({ uri: “https://your-prismic-project.prismic.io/graphql”, }),
cache: new InMemoryCache({
fragmentMatcher: new IntrospectionFragmentMatcher({ introspectionQueryResultData: { __schema: { types: , }, }, })
})
});
async function runQuery(query, variables = null) {
const result = await client.query({query, variables});
if (result) return result.data;
else return null;
}