jakkiraju
06/24/2017, 4:41 PMUnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: "listener" argument must be a function
jakkiraju
06/24/2017, 4:41 PMsebd
06/24/2017, 4:43 PMflorian
06/24/2017, 4:45 PMflorian
06/24/2017, 4:45 PMquery DocumentQuery($locale: String!, $tags: [String!]) {
_allDocumentsMeta(
filter:{
locale: $locale,
published: true,
tags_some: {
content_in: $tags
}
}
){
count
}
allDocuments(
filter:{
locale: $locale,
published: true,
tags_some: {
content_in: $tags
}
}
) {
id,
file {
name,
url
},
title,
description,
tags {
id,
content
}
}
}
florian
06/24/2017, 4:46 PM$tags===[]
?mc_lovin
06/24/2017, 6:39 PM_
as the first arg
var queryType = new graphql.GraphQLObjectType({
name: 'Query',
fields: {
user: {
type: userType,
// `args` describes the arguments that the `user` query accepts
args: {
id: { type: graphql.GraphQLString }
},
resolve: function (_, {id}) {
return fakeDatabase[id];
}
}
}
});
while in static implementation it is something like
var root = {
ip: function (args, request) {
return request.ip;
}
};
mc_lovin
06/24/2017, 6:40 PMagartha
06/24/2017, 6:43 PMjosiah
06/24/2017, 6:44 PMjosiah
06/24/2017, 6:47 PMjosiah
06/24/2017, 6:52 PMgeekodour
06/24/2017, 7:54 PMgeekodour
06/24/2017, 7:55 PMError: GraphQL error: Unknown argument 'authProvider' on field 'createUser' of type 'Mutation'. (line 2, column 14):
createUser(authProvider: {auth0: {idToken: $idToken}}) {
^
Stack trace:
ApolloError@http://localhost:3000/static/js/bundle.js:11384:21
QueryManager.prototype.mutate/</<@http://localhost:3000/static/js/bundle.js:29138:33
geekodour
06/24/2017, 7:55 PMgeekodour
06/24/2017, 7:58 PMgeekodour
06/24/2017, 7:58 PMgeekodour
06/24/2017, 7:59 PMexport const CREATE_USER = gql`mutation ($idToken: String!){
createUser(authProvider: {auth0: {idToken: $idToken}}) {
id
}
}`
geekodour
06/24/2017, 7:59 PMagartha
06/24/2017, 8:03 PMgeekodour
06/24/2017, 8:10 PMgeekodour
06/24/2017, 8:12 PMgeekodour
06/24/2017, 8:12 PMimport React from 'react'
import Auth0Lock from 'auth0-lock'
import { graphql } from 'react-apollo'
import { CREATE_USER } from '../mutations'
import { USER_QUERY } from '../queries'
const LoginAuth0 = props => {
const _lock = new Auth0Lock('lnmp9wV665254625hfX4', '<http://geeko222.auth0.com|geeko222.auth0.com>');
_lock.on('authenticated', (authResult) => {
window.localStorage.setItem('auth0IdToken', authResult.idToken);
console.log('gotcha!');
createUser();
})
const createUser = () => {
const variables = {
idToken: window.localStorage.getItem('auth0IdToken')
}
props.createUser({ variables })
.then((response) => {
console.log('DONE');
}).catch((e) => {
console.error(e)
})
}
return (
<button onClick={()=>(_lock.show())}>Login</button>
)
}
const LoginCREATE_USER = graphql(CREATE_USER,{
props: ({ ownProps, mutate }) => ({
createUser: ({ idToken }) =>
mutate({
variables: { idToken },
})
}),
name: 'createUser'})(LoginAuth0)
export default graphql(USER_QUERY,{ options: { fetchPolicy: 'network-only' } })(LoginCREATE_USER)
jakkiraju
06/24/2017, 8:12 PMError: GraphQL Error: The provided idToken is invalid. Please see <https://auth0.com/docs/tokens/id_token> for how to obtain a valid idToken
at Transport.handleErrors (index.js:70)
at index.js:142
at <anonymous>
jakkiraju
06/24/2017, 8:14 PMjakkiraju
06/24/2017, 8:14 PM_maybeCreateUser = async () => {
const headers = {
'Authorization': `Bearer ${this.state.auth0IdToken}`
}
const transport = new Transport(graphcoolEndpoint, {headers})
const api = new Lokka({ transport })
// check if a user is already logged in
const userResult = await api.query(`{
user {
id
}
}`)
if (!userResult.user) {
console.log("user does not exist");
console.log(this.state.auth0IdToken);
// need to create user
try {
await api.mutate(`{
createUser(authProvider: {
auth0: {
idToken: "${this.state.auth0IdToken}"
}
}) {
id
}
}`)
} catch (e) {
console.log(e);
console.log('could not create user')
// logout to clear a potential existing auth0 token that is invalid
this._logout()
}
}
}
bcbrian
06/24/2017, 8:21 PMthis._lock = new Auth0Lock(props.clientId, props.domain)
jakkiraju
06/24/2017, 8:23 PMjakkiraju
06/24/2017, 8:23 PMchicagoboy2011
06/24/2017, 8:48 PM