Mutation
Mutation: {
signUp: (_, { res }) => {
try {
res.cookie("jwt", "token", {
httpOnly: true
});
return "Amasia";
} catch (error) {
return "error";
}
};
}
Apollo-clenet-react
const [addTodo, { loading, error, data }] = useMutation(gql);
const [formSignUp, setFormSignUp] = useState({
lastName: '',
firstName: '',
password: '',
email: '',
});
const change = e => {
const { value, name } = e.target;
setFormSignUp({ ...formSignUp, [name]: value });
};
When i make a request from react. Here is the answer I get from the server.
1)Data {"data": {"signUp": "Amasia"}}
2) Network
Application
Well when I look in Application Cookies, it is empty.
What am I doing wrong Why are cookies empty?
problem in apollo-client and apollo-server settings (apollo-cookie).
I set up like that.
apollo-client
import { render } from 'react-dom';
import React, { Suspense } from 'react';
import { ApolloClient } from 'apollo-client'
import { ApolloProvider } from 'react-apollo';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { createHttpLink } from 'apollo-link-http';
import './i18n';
import Loading from './component/loading';
import RouteProj from './router';
const link = createHttpLink({
uri: 'http://localhost:8000/graphql',
credentials: 'include'
});
const client = new ApolloClient({
cache: new InMemoryCache(),
link,
});
render(
<ApolloProvider client={client}>
<Suspense fallback={<Loading />}>
<RouteProj/>
</Suspense>
</ApolloProvider>,
document.getElementById('root'),
);
apollo-server
import cors from "cors";
import express from "express";
import { ApolloServer } from "apollo-server-express";
import mongoose from "mongoose";
import schema from "./schema";
import resolvers from "./resolvers";
import models from "./models";
const app = express();
var corsOptions = {
origin: "http://localhost:3000",
credentials: true
};
app.use(cors(corsOptions));
const server = new ApolloServer({
typeDefs: schema,
resolvers,
context: ({ res }) => ({
res
})
});
server.applyMiddleware({ app, path: "/graphql", cors: false });
app.listen({ port: 8000 });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With