First time using Hot Chocolate and Apollo and I have an issue where the Apollo client created always returns 404 for the Hot Chocolate API. This API is running on localhost and can be queried fine.
Whats weird is, if I use the Apollo Client getServerSideProps
, the query returns fine.
EG This is working
export async function getServerSideProps() {
const { data } = await client.query({
query: gql`
query {
rolesQuery {
roles {
id
name
}
}
}
`,
});
return {
props: { roles: data.rolesQuery.roles, },
};
}
This does not
export function createApolloClient() {
const httpLink = createHttpLink({
uri: process.env.NEXT_PUBLIC_GRAPHQL_API,
fetchOptions: {
mode: 'no-cors',
},
});
const client = new ApolloClient({
link: httpLink,
cache: new InMemoryCache(),
});
return client;
}
// Usage of the client
const apolloClient = createApolloClient();
<ApolloProvider client={apolloClient}>...</ApolloProvider>
At first I had a CORS issue which is fixed but I'm still getting a 404 when calling this from a hook inside a component (using graphql-codegen version 2.6.1).
Any ideas?
Edit Front end component calling mutation
import React from "react";
import { gql, useMutation } from '@apollo/client';
const REGISTER = gql`
mutation RegisterUser ($email: String!, $password: String!) {
usersMutation {
registerUser (request: { email: $email, password: $password}) {
id
firstName
email
}
}
}
`;
const SignUp = () => {
const [registerUser, { data, loading, error }] = useMutation(REGISTER);
console.log(registerUser())
return <div>code removed for brevity </div>;
};
export default SignUp;