0

I'm using AWS Amplify, React Native, and Expo to make an app. My DynamoDB tables are set up via a schema.graphql file, and I've generated a bunch of mutations in a mutations.js file. I want to call the following mutations.js mutation from my HomeScreen.js screen file:

export const createConversation = `mutation CreateConversation(
  $input: CreateConversationInput!
  $condition: ModelConversationConditionInput
) {
  createConversation(input: $input, condition: $condition) {
    id
    centralStatement {
      id
      description
      evidence {
        id
        description
        source
        userScores
      }
      source
      userScores
    }
    participants {
      id
      username
      conversations {
        id
      }
    }
  }
}
`;

Then I call this mutation in HomeScreen.js via a "Start a conversation" button:

import { API, graphqlOperation } from 'aws-amplify'
import { createConversation } from '../src/graphql/mutations'

export default function HomeScreen() {

    let handleConvoStartPress = async () => {

        let convoData = {
            id: 'blah',
            centralStatement: {
                id: 'blah',
                description: 'blah',
                evidence: {
                    id: 'blah',
                    description: 'blah',
                    source: 'blah',
                    userScores: 'blah',
                },
                source: 'blah',
                userScores: 'blah',
            },
            participants: {
                id: 'blah',
                username: 'blah',
                conversations: {
                    id: 'blah',
                },
            },
        };

        let newConvo = await API.graphql(graphqlOperation(createConversation, {input: convoData}))
        console.log('*** Success ***');
        console.log(newConvo);
    }

    return (
        <View>
            <ScrollView>
                <View>
                    <TouchableOpacity onPress={handleConvoStartPress}>
                        <Text>
                            Start a conversation
                        </Text>
                    </TouchableOpacity>
                </View>
            </ScrollView>
        </View>
    );
}

But when I press "Start a conversation" I get this error:

Possible Unhandled Promise Rejection (id: 0):
Object {
  "data": Object {},
  "errors": Array [
    [GraphQLError: Request failed with status code 403],
  ],
}

-which I think (from this) means I need to add a X.509 certificate or AWS access key ID. How do I do that? I'm struggling to find the right instructions/examples.

Seelab
  • 1
  • 1
  • A 403 error means that the request is forbidden for a reason. AWS should be returning a header with further info about it - can you see the headers on the response? https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-troubleshoot-403-forbidden/ – Zack Mar 16 '20 at 00:49
  • Thanks @Zack -How do I look for headers of the response (to let newConvo = await API.graphql() )? newConvo doesn't get set, right? Where is the response itself saved? – Seelab Apr 13 '20 at 00:19
  • check out this answer - https://stackoverflow.com/questions/52224958/view-network-traffic-using-react-native-debugger. If you enable network traffic debugging for your react native app, you should be able to capture the request and response with headers in both directions. – Zack Apr 15 '20 at 18:11

0 Answers0