I am trying to get the reaction count for each content using the Github v4 API (GraphQL). Can anyone suggest how can I achieve this?
Github supports the following reactions:
THUMBS_UP
THUMBS_DOWN
LAUGH
HOORAY
CONFUSED
HEART
ROCKET
EYES
For each reaction, I want a count which denotes the number of people who reacted. For eg. I am referring to this comment -> #2190.
Github API provides a feature called reaction group. Refer to the following query...
{
repository(owner: "sindresorhus", name: "refined-github") {
issue(number: 2190) {
reactionGroups {
content
users {
totalCount
}
}
}
}
}
Hope this solves your problem!
Related
According to this documentation:
https://shopify.dev/custom-storefronts/products/filter-products#query-products-by-type
We should be able to filter products within a collection using collectionByHandle.
I have created a very basic test query in the Shopify GraphiQL App explorer tool. When I run the documented query, it returns all products, not filtering at all. See below:
This looks like a bug with the API right? Or am I missing something basic?
OK this turned out to be a configuration issue. To allow filtering by product type, it needs to be turned on in the admin for your store. If you navigate to:
Online Store > Navigation
... and scroll to the bottom, you will see where you can add allowed filters:
Even if it says your theme doesn't support filters, it will still change the way the API behaves.
I have the same problem, the filters param of products query seem to be ineffective and returning me all the products in the collection.
I can't find the "allowed filters" option.
Currently I'm using the Storefront API as an external app, all works fine except that.
Here the code.
query (
$collectionHandle: String, $product_filters: [ProductFilter!], $nQueryElements: Int
) {
collection(handle: $collectionHandle) {
title
products(first: $nQueryElements filters: $product_filters) {
pageInfo {
hasNextPage
hasPreviousPage
}
edges {
cursor
node {
title
vendor
availableForSale
id
handle
productType
variants(first: 40) {
edges {
node {
selectedOptions {
name
value
}
title
compareAtPriceV2 {
amount
}
image {
id
}
}
}
}
priceRange {
maxVariantPrice {
amount
}
}
images(first: 1) {
edges {
node {
id
url(transform: { maxWidth: 500, maxHeight: 700 })
}
}
}
}
}
}
}
}
const variables = { collectionHandle: this.pageURL, nQueryElements: this.nQueryElements, lastCursor: this.queryCursor.last, firstCursor: this.queryCursor.first, product__filters: [{ productVendor: "ASPESI", },], };
Thanks to who can help.
This can be done now. This post on the Shopify forum explains it perfectly with the latest API.
In case that post gets deleted, I'm going to put the info below:
We can now filter by metafields but through a collection. https://shopify.dev/custom-storefronts/products-collections/filter-products#query-products-by-metafi...
Requirements:
The metafield must have been added as a filter in the "Search &
Discovery app" or the Filters in the Navigation settings.
The metafield must be of one of these types: single_line_text_field,
boolean, numeric_integer, numeric_decimal
The Storefront API used must be 2022-04 or higher. I tested it with
2022-10
The metafield must be exposed to the Storefront API
Knowing that as of today, we have a limit of 5000 products for filters to work in a normal store (see https://help.shopify.com/en/manual/online-store/search-and-discovery/filters)
I decided to test if that restriction applies to the Storefront API, I tested it with a collection with 11769 products and I was able to get filtered results as expected. So it seems that at this stage we don't have this limitation in the Storefront API
.
I try for few days to sort my Asset media by the tag than I added on each Asset in Contentful, but I failed on each try...
See my previous question about that sort content by tag in Gatsby with Conteful API
So I'm back to a simplest configuration, just sort the raw asset !
What is good sentence to write sort and filter to catch only the media with tag artWork?
Because I try to understand the gatsby example for that... and it's not easy
https://www.gatsbyjs.com/plugins/gatsby-source-contentful/#contentful-tags
{
allContentfulAsset() {
edges {
node {
title
}
}
}
}
Sort allContentAsset by tag in Gatsby is it possible?
Absolutely. You only need to apply one of the multiple GraphQL filters in Gatsby's implementation. For example:
{
allContentfulAsset(
filter: {
metadata: { tags: { in: ["art work", "vies paralleles"] } }
}
) {
edges {
node {
title
}
}
}
}
The previous snippet will get allContentfulAsset where those tags contain "art work" and "vies paralleles". Assuming the interpolation between assets and tags exists (i.e: tags is selectable a field in assets). If this interpolation is not present or it's not properly done, allContentfulAsset will never have tags to filter so your query will break.
Keep in mind that to use tags, you need to set the enableTags flag as true (set as default as false) by:
{
resolve: `gatsby-source-contentful`,
options: {
spaceId: process.env.CONTENTFUL_SPACE_ID,
accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
enableTags: true,
},
},
According to this pull-request the enableTags feature was fixed in the cutting-edge release(5 days ago) so try to upgrade your plugin dependency.
It should be fixed in (inferred in this GitHub thread):
gatsby-source-contentful#7.5.0-next.0
Please provide feedback on previous questions/answers rather than keep opening new ones. Even delete the previous ones or provide feedback about what you've tried...
I can get room's clients list with this code in socket.io 0.9.
io.sockets.clients(roomName)
How can I do this in socket.io 1.0?
Consider this rather more complete answer linked in a comment above on the question: https://stackoverflow.com/a/24425207/1449799
The clients in a room can be found at
io.nsps[yourNamespace].adapter.rooms[roomName]
This is an associative array with keys that are socket ids. In our case, we wanted to know the number of clients in a room, so we did Object.keys(io.nsps[yourNamespace].adapter.rooms[roomName]).length
In case you haven't seen/used namespaces (like this guy[me]), you can learn about them here http://socket.io/docs/rooms-and-namespaces/ (importantly: the default namespace is '/')
Updated (esp. for #Zettam):
checkout this repo to see this working: https://github.com/thegreatmichael/socket-io-clients
Using #ryan_Hdot link, I made a small temporary function in my code, which avoids maintaining a patch. Here it is :
function getClient(roomId) {
var res = [],
room = io.sockets.adapter.rooms[roomId];
if (room) {
for (var id in room) {
res.push(io.sockets.adapter.nsp.connected[id]);
}
}
return res;
}
If using a namespace :
function getClient (ns, id) {
return io.nsps[ns].adapter.rooms[id]
}
Which I use as a temporary fix for io.sockets.clients(roomId) which becomes findClientsSocketByRoomId(roomId).
EDIT :
Most of the time it is worth considering avoiding using this method if possible.
What I do now is that I usually put a client in it's own room (ie. in a room whose name is it's clientID). I found the code more readable that way, and I don't have to rely on this workaround anymore.
Also, I haven't tested this with a Redis adapter.
If you have to, also see this related question if you are using namespaces.
For those of you using namespaces I made a function too that can handle different namespaces. It's quite the same as the answer of nha.
function get_users_by_room(nsp, room) {
var users = []
for (var id in io.of(nsp).adapter.rooms[room]) {
users.push(io.of(nsp).adapter.nsp.connected[id]);
};
return users;
};
As of at least 1.4.5 nha’s method doesn’t work anymore either, and there is still no public api for getting clients in a room. Here is what works for me.
io.sockets.adapter.rooms[roomId] returns an object that has two properties, sockets, and length. The first is another object that has socketId’s for keys, and boolean’s as the values:
Room {
sockets:
{ '/#vQh0q0gVKgtLGIQGAAAB': true,
'/#p9Z7l6UeYwhBQkdoAAAD': true },
length: 2 }
So my code to get clients looks like this:
var sioRoom = io.sockets.adapter.rooms[roomId];
if( sioRoom ) {
Object.keys(sioRoom.sockets).forEach( function(socketId){
console.log("sioRoom client socket Id: " + socketId );
});
}
You can see this github pull request for discussion on the topic, however, it seems as though that functionality has been stripped from the 1.0 pre release candidate for SocketIO.
I need some help with pseudocode. The question is as follows:
Write pseudocode for a function, processPayment() that processes
payment by customers and commits the system to delivering the promised
product and service. This function may call on other functions,
possibly from other objects. You do not have to describe the called
functions or the classes that they belong to as long the calls are
reasonably explanatory.
Advertising is displayed while the customer
awaits credit approval. (i.e., you can assume that while the function
is waiting for credit card approval to complete, the next step begins
immediately.)
Advertising is removed as soon as credit acceptance or
denial is received. You can assume that the user has already entered
credit card information and is aware of the costs of each option.
I have this as pseudocode:
processPayment()
do displayAdContent();
while paymentConfirmation(bool) = false;
I keep thinking I need something after processPayment(). Any guidance would be appreciated!
You need a lot more than "something after processPayment()." I would do something like this:
ProcessPayment()
{
if(paymentIsValid)
{
do displayAdContent();
if(isInInventory())
{
try
{
do createAndChargeOrder();
do deliverProduct();
do updateInventory();
}
catch
{
do cancelOrder();
do sendFailedOrderNotification();
}
}
else
{
do notifyNotAvailable();
do offerSimilarProduct();
}
do sendConfirmation();
}
else
{
do paymentNotValid();
}
}
https://google-developers.appspot.com/maps/documentation/javascript/examples/places-autocomplete
I have a page similar to the above google places autocomplete demo url whereby if i type Buckingham Palace. It will return results of
Buckingham Palace Road, London, United Kingdom
Buckingham Palace Shop, Buckingham Palace Road, Victoria, London,
United Kingdom
and etc. How do i remove London, United Kingdom from the results?
It seems Google have no interest in sorting it out anytime soon. I have had to resort to the following, might be sufficient for others' needs as well:
document.addEventListener('DOMNodeInserted', function(event) {
var target = $(event.target);
if (target.hasClass('pac-item')) {
target.html(target.html().replace(/, Australia<\/span>$/, "</span>"));
}
});
note that pac-item is the class used on each suggestion. See Google Reference for other classes used. The container with pac-container class seems to drop the items when it is not shown and add new ones when it displays so if these pac-items are getting added to the DOM, it means suggestions are on their way to be displayed and pac-container is about to become visible.
just worked this out so open to improvements.
This also is not a complete solution. When selecting a suggestion with the country removed, autocomplete still adds the country to the geocoding! place_changed is too late a stage to change that so please see the solution above as only part of the answer. I'll update this again once I figure out the rest.
--- update
personally, i ended up not using the google autocomplete at all as i couldn't find a way around the problem of the autocomplete still showing the country once a modified suggestion is selected. a more usable approach was to use twitter typeahead and use the google APIs for getting the suggestions only. this gave me more control over the suggestions but obviously requires more manual work to make up for lost functionality
Here is How I made it work with jQuery auto-complete. Hope it helps someone.
$("#Search").autocomplete({
source: function (request, response) {
var options = {
input: request.term,
types: ['(cities)'],
region: 'US',
componentRestrictions: { country: "us" }
};
function callback(predictions, status) {
for (var i = 0, prediction; prediction = predictions[i]; i++) {
results.push(prediction.description.replace(/, United States$/, ""));
}
response(results);
}
var service = new google.maps.places.AutocompleteService();
service.getPlacePredictions(options, callback);
var results = [];
}
});
This is not possible without manually processing the results. If you think that it would be a useful feature, please file a Places API - Feature Request.