Use this recipe to send the token with your graphc...
# prisma-whats-new
m
Use this recipe to send the token with your graphcool request: http://dev.apollodata.com/react/auth.html
b
thanks @matty so I went with the cookie option to pass the token to be able to render SSR. in my client i added:
Copy code
const networkInterface = createNetworkInterface({
  uri: 'my-uri',
  opts: {
    credentials: 'same-origin',
  },
});
const client = new ApolloClient({
  networkInterface,
});
and in my server with the
cors
package,
Copy code
var corsOptions = {
  origin: '<insert uri of front-end domain>',
  credentials: true // <-- REQUIRED backend setting
};
app.use(cors(corsOptions));
but when I
console.log(req)
in the server, what am i supposed to look for to extract the credential token?
m
a) if you're sending the token in the request to the server, and you're using express/connect, add this to your middleware: https://www.npmjs.org/package/cookie-parser
b) you also need to think about the client making graphql queries directly (i.e. not as part of the initial page rendering flow)
b
@matty yup I tried to but I am using react and react-apollo. The problem I am facing is because this one component requires a ‘user’ props that is returned from a query. And I am unsure of how to pass a value returned from a query as props into the component
Copy code
const componentApollo = compose(
  withApollo,
  graphql(getAllAssets, {name: 'getAllAssets'}),
  graphql(getUserAssets, {
    options: ({user}) => ({variables : {userId: user.id}})
  })
)(ComponentContainer)
so the easiest way i found is to just query the user in a parent component and then pass it down as props into this ComponentContainer
m
@be4r if you're querying graphcool for fields (including nested fields) on the currently logged in user, you don't need to fetch the user first. Simply do something like
query { user { firstName, lastName, emailAddress } }