How do we know when "refetchQueries" completed in graphql? - graphql

I am doing a mutation :
const responseData = await updateCompany({
variables: {
form_data
},
fetchPolicy: 'no-cache',
refetchQueries: [{ query: getCompanyProfileDataQuery }],
awaitRefetchQueries: true
});
Mutation and re-fetch query is working perfectly.
But I want to write some code just after re-fetch query completed.
So how do we know when our re-fetch query completed ?

Related

graphql 400 bad request - Must provide an operation

I am trying to hit a GraphQL query in Postman but it is giving 400 bad request error.
Query is:
type Query {
school(id: ID, schoolCode: String): School
}
type School {
optionalSubjects: [String!]
code: ID!
defaultSubjects: String!
defaultExams: String!
}
What am I missing here? I am new to GraphQL so I am not getting the cause of this error. Do I need to provide values on the right side of Postman under GRAPHQL VARIABLES section?
400 bad request in graphql
React Apollo GraphQL Mutation returns 400 (bad request)
Graphql POST call gives 400 bad request error
The problem is in the error. It says
Must provide an operation
what you're doing is executing the type definition. That's like executing a function interface definition rather than the function itself in typescript.
As an example, I have a type definition like
const Comment = new GraphQLObjectType({
name: "Comment",
fields: {
id: { type: new GraphQLNonNull(GraphQLID) },
content: { type: new GraphQLNonNull(GraphQLString) },
email: { type: new GraphQLNonNull(GraphQLString) },
createdAt: {
type: new GraphQLNonNull(GraphQLString),
resolve: (source) => source.createdAt.toISOString(),
},
postId: { type: new GraphQLNonNull(GraphQLID) },
},
});
followed by this query
commentMainList: {
type: new GraphQLList(new GraphQLNonNull(Comment)),
resolve: async (source, args, { pgApi }) => {
return pgApi.commentMainList();
},
},
and then in postman I can do
{
commentMainList{
id
postId
email
content
createdAt
}
}

does the amplify graphql api-key inside a lambda function expire?

I have a time triggered lambda function in amplify and it works fine:
url: process.env.API_P2PCHAKRA_GRAPHQLAPIENDPOINTOUTPUT,
method: 'post',
headers: {
'x-api-key': process.env.API_P2PCHAKRA_GRAPHQLAPIKEYOUTPUT
},
data: {
query: print(listorderstatuss ),
variables: {
limit: 100,
nextToken: nextToken
}
}
}) ;
my question is do I have to worry about api-key expiration ? Or is amplify/AWS doing something in the background I don't understand.

How to remove previous data when executing AJAX request multiple times

I have an issue with ajax calling. It works correct except one thing, when I try to get data with the same option more than one times returns the new response but also still return the data of the previous response.
I think that there is something that I've missed.
ajax script
$('#search').on('click', function () {
var date = $("#date").val();
$.ajax({
type: 'GET',
url: '{{Route("dashboard.status")}}',
data: {
date: date
},
dataType: "JSon",
success: function(response){
console.log(response.manager_hourlog);
// Employee report script
var colors = ["#1abc9c", "#2ecc71", "#3498db", "#9b59b6", "#34495e", "#16a085", "#27ae60", "#2980b9", "#8e44ad", "#2c3e50", "#f1c40f", "#e67e22", "#e74c3c", "#ecf0f1", "#95a5a6", "#f39c12", "#d35400", "#c0392b", "#bdc3c7", "#7f8c8d"];
#if ($auth->user_type != 1)
// manager report script
var managerchartbar = {
labels: response.manager_projects,
datasets:
[{
label: response.users,
backgroundColor: colors[Math.floor(Math.random() * colors.length)],
data: response.totals
},]
};
var ctx = document.getElementById('manager').getContext('2d');
window.myBar = new Chart(ctx, {
type: 'bar',
data: managerchartbar,
options: {
title: {
display: true,
text: 'Project Report chart'
},
tooltips: {
mode: 'index',
intersect: false
},
responsive: true,
scales: {
xAxes: [{
stacked: true,
}],
yAxes: [{
stacked: true
}]
}
}
});
#endif
},
error: function(xhr){
console.log(xhr.responseText);
}});
});
});
</script>
You should change your method to POST for json request/response API, will be more secure and avoid laravel cache view it.
type: 'POST',
Try to change method to POST (do same for your api server and route).
If not work, please show your laravel API code.
you should set cache property to false or append "_={timestamp}" to the GET parameter
so add cache to your request:
cache:false
or append timestamp to your url:
url: '{{Route("dashboard.status")}}'+'_='+ + new Date().getTime(),

get data showing in console but not in array laravel vue

here is my app.js looks like
const app = new Vue({
el: '#app',
data: {
msg: 'Update new Post:',
content:'',
posts:[],
},
ready:function(){
this.created();
},
created(){
axios.get('http://{mydomain}/home/post')
.then(response=>{
console.log(response);//show if success
this.posts=respoonse.data;// putting posts into array
})
.catch(function (error) {
console.log(error.response);
});
},
my view page looks like
#{{posts}}
and my controller looks like
public function getPost(){
$posts_json = DB::table('posts')
->leftJoin('users','users.id','posts.user_id')
->leftJoin('profiles','profiles.user_id','posts.user_id')
->get();
return $posts_json;
}
its showing nothing in the array but data showing in console
{data: Array(9), status: 200, statusText: "OK", headers: {…}, config: {…}, …}

Angular.js - How to keep data up to date?

If I have the following factories:
.factory('User', function($resource) {
return $resource('/users/:id', {id: "#id"}, {
query: {method: 'GET', params: {}, isArray: false}
});
})
.factory('UserList', function(User, $q) {
var deferred = $q.defer();
User.query({}, function(response) {
deferred.resolve(response.data);
});
return deferred.promise;
})
I know have a UserList that I can inject into all my controllers that need it. But, if I later in my application create a new user, how can I make the 'UserList'-factory "refresh"? Is there another approach that is (even) more "The Angular Way"?

Resources