aws-amplify#graphqlOperation JavaScript Examples
The following examples show how to use
aws-amplify#graphqlOperation.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From InstagramClone with MIT License | 6 votes |
Feed = () => {
const [posts, setPosts] = useState([]);
useEffect(() => {
fetchPosts();
}, [])
const fetchPosts = async () => {
try {
const postsData = await API.graphql(graphqlOperation(listPosts));
setPosts(postsData.data.listPosts.items);
} catch (e) {
console.log(e.message);
}
}
return (
<FlatList
data={posts}
renderItem={({item}) => <Post post={item} />}
keyExtractor={({id}) => id}
ListHeaderComponent={Stories}
/>
)
}
Example #2
Source File: index.js From InstagramClone with MIT License | 6 votes |
Stories = () => {
const [stories, setStories] = useState([]);
useEffect(() => {
fetchStories();
}, []);
const fetchStories = async () => {
try {
const storiesData = await API.graphql(graphqlOperation(listStorys));
setStories(storiesData.data.listStorys.items);
} catch (e) {
console.log(e);
}
}
return (
<FlatList
data={stories}
keyExtractor={({user: {id}}) => id}
horizontal
showsHorizontalScrollIndicator={false}
style={styles.container}
renderItem={({item}) => <Story story={item}/>}
/>
)
}
Example #3
Source File: App.js From react-admin-amplify-demo with MIT License | 6 votes |
// Get the demo user avatar
authProvider.getIdentity = async () => {
try {
const userData = await API.graphql(
graphqlOperation(queries.getUser, { id: "demo" })
);
const url = await Storage.get(userData.data.getUser.picture.key);
return {
id: "demo",
fullName: "Demo",
avatar: url,
};
} catch (e) {
console.log(e);
}
};
Example #4
Source File: AgentAssist.js From chime-voiceconnector-agent-assist with MIT No Attribution | 6 votes |
async componentDidMount() {
const transcript = await this.readTranscriptPaginationAndUpdate();
this.setState({ transcript: transcript });
const observable = await API.graphql(graphqlOperation(anncTranscript));
const addSegmentToState = segment => {
this.setState(state => {
const updatedTranscript = state.transcript.slice();
updatedTranscript.push(segment);
return {
transcript: updatedTranscript,
};
});
};
const updateTranscript = data => {
const segment = data.value.data.onAnnounceCreateTranscriptSegment;
addSegmentToState(segment);
return;
};
observable.subscribe({
next: updateTranscript,
complete: console.log,
error: console.error,
});
}
Example #5
Source File: AgentAssist.js From chime-voiceconnector-agent-assist with MIT No Attribution | 6 votes |
async readTranscriptPaginationAndUpdate() {
let transcript = [];
const firstPage = await API.graphql(graphqlOperation(readTranscript));
let nextToken = firstPage.data.listTranscriptSegments.nextToken;
transcript = transcript.concat(firstPage.data.listTranscriptSegments.items);
while (nextToken !== null) {
const nextPage = await API.graphql(
graphqlOperation(readTranscript, { nextToken: nextToken })
);
nextToken = nextPage.data.listTranscriptSegments.nextToken;
transcript = transcript.concat(nextPage.data.listTranscriptSegments.items);
}
return transcript;
}
Example #6
Source File: GraphQLHandler.js From aws-perspective with Apache License 2.0 | 5 votes |
deleteAccounts = (accountIds) => {
return API.graphql(graphqlOperation(mutations.deleteAccounts, accountIds));
}
Example #7
Source File: GraphQLHandler.js From aws-perspective with Apache License 2.0 | 5 votes |
deleteRegions = (params) => {
return API.graphql(graphqlOperation(mutations.deleteRegions, params));
}
Example #8
Source File: GraphQLHandler.js From aws-perspective with Apache License 2.0 | 5 votes |
addRegions = (params) => {
return API.graphql(graphqlOperation(mutations.addRegions, params));
}
Example #9
Source File: GraphQLHandler.js From aws-perspective with Apache License 2.0 | 5 votes |
addAccounts = (params) => {
return API.graphql(graphqlOperation(mutations.addAccounts, params));
}
Example #10
Source File: GraphQLHandler.js From aws-perspective with Apache License 2.0 | 5 votes |
getAccount = (account) => {
return API.graphql(graphqlOperation(queries.getAccount, account));
}
Example #11
Source File: GraphQLHandler.js From aws-perspective with Apache License 2.0 | 5 votes |
getAccounts = () => {
return API.graphql(graphqlOperation(queries.getAccounts, {}));
}
Example #12
Source File: App-05.js From workshop-aws-getting-started-amplify with MIT License | 5 votes |
async componentDidMount() {
var result = await API.graphql(graphqlOperation(listNotes));
this.setState({ notes: result.data.listNotes.items });
}
Example #13
Source File: App-04.js From workshop-aws-getting-started-amplify with MIT License | 5 votes |
async componentDidMount() {
var result = await API.graphql(graphqlOperation(listNotes));
this.setState({ notes: result.data.listNotes.items });
}
Example #14
Source File: App-03.js From workshop-aws-getting-started-amplify with MIT License | 5 votes |
async componentDidMount(){
var result = await API.graphql(graphqlOperation(listNotes));
this.setState( { notes: result.data.listNotes.items } )
}
Example #15
Source File: Notes.js From aws-amplify-quick-notes with MIT No Attribution | 5 votes |
NotesComponent = () => {
const [notes, setNotes] = useState([]);
useEffect(() => {
const fetchNotes = async () => {
const result = await API.graphql(graphqlOperation(listNotes));
setNotes(
result.data.listNotes.items.sort((a, b) => {
if (a.updatedAt > b.updatedAt) return -1;
else return 1;
})
);
};
fetchNotes();
}, []);
return (
<Container>
{notes.map(note => (
<Note
key={note.id}
{...note}
onSaveChanges={async values => {
const result = await API.graphql(
graphqlOperation(updateNote, {
input: {
...note,
...values
}
})
);
setNotes(
notes.map(n => {
return n.id === note.id ? result.data.updateNote : n;
})
);
}}
onDelete={async () => {
await API.graphql(
graphqlOperation(deleteNote, {
input: {
id: note.id
}
})
);
setNotes(notes.filter(n => n.id !== note.id));
}}
/>
))}
</Container>
);
}
Example #16
Source File: Canvas.js From aws-amplify-appsync-graphql-real-time-canvas with MIT No Attribution | 5 votes |
componentDidMount() {
const canvas = {
id: this.id,
clientId: this.clientId,
data: {
...this.state,
lines: []
}
}
// Create the canvas. If canvas is already created, retrieve the data & draw previous canvas
API.graphql(graphqlOperation(createCanvas, { input: canvas }))
.then(d => console.log('canvas created :', d))
.catch(err => {
if (err.errors[0].data.id === this.id) {
const d = err.errors[0].data.data
this.canvas.loadSaveData(d)
}
})
window.addEventListener('mouseup', (e) => {
// If we are clicking on a button, do not update anything
if (e.target.name === 'clearbutton') return
this.setState({
brushColor: rand()
})
const data = this.canvas.getSaveData()
const p = JSON.parse(data)
const length = p.lines.length
this.lineLength = length
const canvas = {
id: this.id,
clientId: this.clientId,
data
}
// Save updated canvas in the database
API.graphql(graphqlOperation(updateCanvas, { input: canvas }))
.then(c => {
console.log('canvas updated!')
})
.catch(err => console.log('error creating: ', err))
})
API.graphql(graphqlOperation(onUpdateCanvas))
.subscribe({
next: (d) => {
const data = JSON.parse(d.value.data.onUpdateCanvas.data)
const length = data.lines.length
if (length === 0) {
// If there is no canvas data, clear the canvas
const data = this.canvas.getSaveData()
const parsedData = JSON.parse(data)
const newData = {
...parsedData,
lines: []
}
const newCanvas = JSON.stringify(newData)
this.canvas.loadSaveData(newCanvas)
return
}
if (this.lineLength === length || length === Number(0)) return
// Draw new lines to canvas
const last = data.lines[length -1]
this.canvas.simulateDrawingLines({ lines: [last] })
}
})
}
Example #17
Source File: Record.js From aws-amplify-quick-notes with MIT No Attribution | 4 votes |
RecordComponent = props => {
const [isRecording, setIsRecording] = useState(false);
const [showRecordingEditor, setShowRecordingEditor] = useState(false);
const [recordingText, setRecordingText] = useState("");
const [isConverting, setIsConverting] = useState("");
const [micStream, setMicStream] = useState();
const [audioBuffer] = useState(
(function() {
let buffer = [];
function add(raw) {
buffer = buffer.concat(...raw);
return buffer;
}
function newBuffer() {
console.log("reseting buffer");
buffer = [];
}
return {
reset: function() {
newBuffer();
},
addData: function(raw) {
return add(raw);
},
getData: function() {
return buffer;
}
};
})()
);
const startRecording = async () => {
const stream = await window.navigator.mediaDevices.getUserMedia({
video: false,
audio: true
});
const startMic = new mic();
startMic.setStream(stream);
startMic.on("data", chunk => {
var raw = mic.toRaw(chunk);
if (raw == null) {
return;
}
audioBuffer.addData(raw);
});
setMicStream(startMic);
setIsRecording(true);
};
const stopRecording = async () => {
micStream.stop();
setIsRecording(false);
setIsConverting(true);
const buffer = audioBuffer.getData();
const result = await Predictions.convert({
transcription: {
source: {
bytes: buffer
}
}
});
setMicStream(null);
audioBuffer.reset();
setRecordingText(result.transcription.fullText);
setIsConverting(false);
setShowRecordingEditor(true);
};
return (
<Container>
<div
css={css`
position: relative;
justify-content: center;
align-items: center;
width: 120px;
height: 120px;
`}
>
<div
css={[
css`
width: 100%;
height: 100%;
top: 0;
left: 0;
position: absolute;
border-radius: 50%;
background-color: #74b49b;
`,
isRecording || isConverting
? css`
animation: ${pulse} 1.5s ease infinite;
`
: {}
]}
/>
<div
css={css`
width: 100%;
height: 100%;
top: 0;
left: 0;
position: absolute;
border-radius: 50%;
background-color: #74b49b;
display: flex;
cursor: pointer;
`}
onClick={() => {
if (!isRecording) {
startRecording();
} else {
stopRecording();
}
}}
>
{isConverting ? (
<FaMicrophoneAltSlash
size={50}
style={{ margin: "auto" }}
/>
) : isRecording ? (
<FaMicrophone
size={50}
style={{ margin: "auto" }}
/>
) : (
<FaMicrophoneAlt
size={50}
style={{ margin: "auto" }}
/>
)}
</div>
</div>
{showRecordingEditor && (
<RecordingEditor
text={recordingText}
onDismiss={() => {
setShowRecordingEditor(false);
}}
onSave={async data => {
await API.graphql(graphqlOperation(createNote, { input: data }));
props.setTabIndex(0);
}}
/>
)}
</Container>
);
}
Example #18
Source File: index.js From InstagramClone with MIT License | 4 votes |
StoryScreen = () => {
const [stories, setStories] = useState([]);
const [activeStoryIndex, setActiveStoryIndex] = useState(null);
const route = useRoute();
useEffect(() => {
fetchStories();
setActiveStoryIndex(0);
}, []);
const fetchStories = async () => {
try {
const storiesData = await API.graphql(graphqlOperation(listStorys));
console.log(storiesData);
setStories(storiesData.data.listStorys.items);
} catch (e) {
console.log('error fetching stories');
console.log(e)
}
}
const handleNextStory = () => {
if (activeStoryIndex >= stories.length - 1) {
return;
}
setActiveStoryIndex(activeStoryIndex + 1);
}
const handlePrevStory = () => {
if (activeStoryIndex <= 0) {
return;
}
setActiveStoryIndex(activeStoryIndex - 1);
}
const handlePress = (evt) => {
const x = evt.nativeEvent.locationX;
const screenWidth = Dimensions.get('window').width;
if (x < screenWidth / 2) {
handlePrevStory();
} else {
handleNextStory();
}
}
if (!stories || stories.length === 0) {
return (
<SafeAreaView>
<ActivityIndicator />
</SafeAreaView>
)
}
const activeStory = stories[activeStoryIndex];
return (
<SafeAreaView style={styles.container}>
<TouchableWithoutFeedback onPress={handlePress}>
<ImageBackground source={{uri: activeStory.image}} style={styles.image}>
<View style={styles.userInfo}>
<ProfilePicture uri={activeStory.user.image} size={50} />
<Text style={styles.userName}>{activeStory.user.name}</Text>
<Text style={styles.postedTime}>{activeStory.createdAt}</Text>
</View>
<View style={styles.bottomContainer}>
<View style={styles.cameraButton}>
<Feather name="camera" size={30} color={'#ffffff'} />
</View>
<View style={styles.textInputContainer}>
<TextInput
style={styles.textInput}
editable
placeholder="Send message"
placeholderTextColor={"white"}
/>
</View>
<View style={styles.messageButton}>
<Ionicons name="paper-plane-outline" size={35} color={"#ffffff"}/>
</View>
</View>
</ImageBackground>
</TouchableWithoutFeedback>
</SafeAreaView>
)
}