How to use the aws-amplify.graphqlOperation function in aws-amplify

To help you get started, we’ve selected a few aws-amplify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws-samples / aws-serverless-airline-booking / src / frontend / store / loyalty / actions.js View on Github external
return new Promise(async (resolve, reject) => {
    Loading.show({
      message: "Loading profile..."
    });

    try {
      const {
        // @ts-ignore
        data: { getLoyalty: loyaltyData }
      } = await API.graphql(graphqlOperation(getLoyalty));
      const loyalty = new Loyalty(loyaltyData);

      commit("SET_LOYALTY", loyalty);

      Loading.hide();
      resolve();
    } catch (err) {
      Loading.hide();
      reject(err);
    }
  });
}
github dabit3 / write-with-me / src / Posts.js View on Github external
async function fetchPosts(dispatch) {
  try {
    const postData = await API.graphql(graphqlOperation(listPosts))
    dispatch({
      type: 'fetchPostsSuccess',
      posts: postData.data.listPosts.items
    })
  } catch (err) {
    console.log('error fetching posts...: ', err)
    dispatch({
      type: 'fetchPostsError',
    })
  }
}
github awsed / appsync-broadcaster-sar / src / App.js View on Github external
async handleSubmit(event) {
    event.preventDefault();
    event.stopPropagation();
    const message = {
      "message":this.state.value
    }
    await API.graphql(graphqlOperation(sendMessage, message));
  }
github dabit3 / aws-amplify-workshop-react-native / graphqlHooks.js View on Github external
const restaurant = {
    name, 
    description,
    city,
    clientId: CLIENTID
  }
  
  const restaurants = [...state.restaurants, restaurant]

  dispatch({
    type: 'set',
    restaurants
  })  

  try {
    await API.graphql(graphqlOperation(createRestaurant, {
      input: restaurant
    }))
    console.log('restaurant created!')
  } catch (err) {
    console.log('error creating restaurant...', err)
  }
}
github aws-samples / aws-serverless-appsync-loyalty / src / components / Points.js View on Github external
async componentDidMount(){
    //Create subscription for real-time points balance update
    this.subscription = API.graphql(graphqlOperation(subscribeToPoints)).subscribe({
      next: (event) => {
          console.log("Subscription: "+event.value.data);
          this.setState({points: event.value.data.subscribeToPoints.points});
      }
    });
  }
github dabit3 / full-stack-react-native-appsync-workshop / AppWithHooks.js View on Github external
const { name, description, city  } = state
  const restaurant = {
    name, 
    description,
    city,
    clientId: CLIENTID
  }
  
  const updatedRestaurantArray = [...state.restaurants, restaurant]
  dispatch({
    type: 'set',
    restaurants: updatedRestaurantArray
  })
  
  try {
    await API.graphql(graphqlOperation(createRestaurant, {
      input: restaurant
    }))
    console.log('item created!')
  } catch (err) {
    console.log('error creating restaurant...', err)
  }
}
github jamstack-cms / jamstack-cms / src / components / settings.js View on Github external
updateSettings = async (input, type) => {
    try {
      await API.graphql(graphqlOperation(createSettings, { input }))
      console.log(`${type} successfully updated...`)
    } catch (err) {
      if (err.errors[0].message.includes('The conditional request failed')) {
        console.log(`${type} already set.... Updating ${type}.`)
        try {
          await API.graphql(graphqlOperation(updateSettings, { input }))
          console.log(`${type} successfully updated...`)
        } catch (err) {
          console.log(`error updating ${type}: `, err)
        }
      }
    }
  }
  updateTheme = theme => {
github dabit3 / speakerchat / src / Talks.js View on Github external
async function fetchTalks(dispatch) {
  try {
    getFromStorage(dispatch)
    const talkData = await API.graphql(graphqlOperation(listTalks))
    console.log('talkData: ', talkData)
    const talks = talkData.data.listTalks.items
    setToStorage(talks)
    dispatch({ type: 'set', talks })
  } catch (error) {
    console.log('error:', error)
    dispatch({ type: 'error', error })
  }
}
github aws-samples / aws-appsync-visualization-with-athena-app / src / App.js View on Github external
const go = async () => {
      const result = await API.graphql(
        graphqlOperation(queries.queryByOwner, {
          owner: user.attributes.sub,
          sortDirection: 'DESC',
          limit: 10
        })
      )
      setpastQueries(result.data.queryByOwner)
    }
    go()