I am using graphlient gem to make a graphql query call
I have to make this call in controller so thats why I am using graphlient ta make call
client = Graphlient::Client.new("http://localhost:3000/graphql", headers: {
'Authorization': "API #{api_key}"
})
response = client.query do
query{
search(id: 1){
edges{
node{
id
name
timing{
start
end
}
}
}
}
end
I have timing field which has two attribute start and end but Rails is giving me syntax error as
end is a keyword in Rails
How can I run this query without syntax error? Is there any way to send the query in string format to run this?
I am assuming that you are using ashkan18/graphlient since this is the first result when searching for graphlient.
And according to its documentation, you can use a string for making queries. So instead of using blocks in your example, you can do this instead:
response = client.query <<~GRAPHQL
query {
search(id: 1) {
edges {
node {
id
name
timing {
start
end
}
}
}
}
}
GRAPHQL
Related
I have a Graphql query working in Graphiql:
query MyConfigurationType {
myConfiguration {
number
expirationDate
}
}
Returns
{
"data": {
"myConfiguration": {
"number": 1,
"expirationDate": "2022/10/04"
}
}
}
But I need to actually use that result in my app therefore I want to be able to run it in my rails console. There doesn't seem to be much info about this.
How would one go about executing a Graphql query in the Rails console?
After looking at some documentation the best I could manage to do was, in the Rails console do:
query_string = "query MyConfigurationType {
myConfiguration {
number
expirationDate
}
}"
and the run
result = MySchema.execute(query_string)
Which has a result of
=> #<GraphQL::Query::Result #query=... #to_h={"data"=>{"myConfiguration"=>{"number"=>1, "expirationDate"=>"2022/10/04"}}}>
Therefore one can now do
[1] pry(main)> result['data']
=> {"myConfiguration"=>{"number"=1, "expirationDate"=>"2022/10/04"}}
I built a simple plugin that shows in the CRMContainer the url of my CRM given some attributes parameters (if they are passed by), during inbound tasks this works fine, but the problem is that during outbound calls the behaviour is not the one expected, this is the piece of code:
flex.CRMContainer.defaultProps.uriCallback = (task) => {
return task
? `https://mycrm.zzz/${task.attributes.clicar}/${task.attributes.contacth}/`
: 'https://mycrm.zzz/contacts/';
}
}
I would need an additional condition that tells the code, if this is an outbound voice call to always show a default url.
I tried adding an if/else that checks if task.attributes.direction is outbound, but Flex says this is undefined.
Any tip?
Thanks
Max
The problem is that you aren't checking for the existence of the task. Your original code had this:
flex.CRMContainer.defaultProps.uriCallback = (task) => {
return task
? `https://mycrm.zzz/${task.attributes.clicar}/${task.attributes.contacth}/`
: 'https://mycrm.zzz/contacts/';
}
}
Which returns the URL with the task attributes in it only if the task exists, because of the ternary conditional.
So, when you try to use the attributes you need to make sure the task exists. So taking your code from the last comment, it should look like this:
flex.CRMContainer.defaultProps.uriCallback = (task) => {
if (task) {
if (task.attributes.direction === 'outbound'){
return `https://mycrm.zzz/${task.attributes.clicar}/${task.attributes.contacth}/`;
} else {
return `https://mycrm.zzz/contacts/`
}
} else {
return 'https://mycrm.zzz/contacts/';
}
}
I'm using the shopify_app gem and trying to get multiple products using the graphql admin API. I can hardcode product Id's and get a valid response. However, when using dynamic variables I get the error below in my terminal:
GraphQL::ParseError (Parse error on "$" (VAR_SIGN) at [2, 27]):
Here is the code block
get_order_products = ShopifyAPI::GraphQL.client.parse <<-'GRAPHQL'
{
query getProducts($ids: [ID!]!) {
nodes(ids: $ids) {
... on Product {
id
title
metafields(first: 5) {
edges {
node {
namespace
key
value
}
}
}
}
}
}
}
GRAPHQL
{
"ids": ["gid://shopify/Product/abc123", "gid://shopify/Product/abc456"]
}
#result = ShopifyAPI::GraphQL.client.query(get_order_products)
I'm new to graphql but would have expected this to work based on this shopify community forum post][1]
I'm trying to bypass a JSON aggregation query to aggregation pipeline of MongoDB.
For doing that I have this endpoint on my RoR app
def index
Lead.collection.aggregate(JSON.parse(params[:query]))
end
And I send this JSON from my frontend
[
{
"$match": {
"statuses.created_at": {
"$gte": {
"$date": "1539369174"
}
}
}
}
]
The problem is that I'm not getting no result because "$date" filter is not working properly.
In mongo shell I'm getting results.
I'm currently trying the Neo4j 2.0.0 M3 and see some strange behaviour. In my unit tests, everything works as expected (using an newImpermanentDatabase) but in the real thing, I do not get results from the graphDatabaseService.findNodesByLabelAndProperty.
Here is the code in question:
ResourceIterator<Node> iterator = graphDB
.findNodesByLabelAndProperty(Labels.User, "EMAIL_ADDRESS", emailAddress)
.iterator();
try {
if (iterator.hasNext()) { // => returns false**
return iterator.next();
}
} finally {
iterator.close();
}
return null;
This returns no results. However, when running the following code, I see my node is there (The MATCH!!!!!!!!! is printed) and I also have an index setup via the schema (although that if I read the API, this seems not necessary but is important for performance):
ResourceIterator<Node> iterator1 = GlobalGraphOperations.at(graphDB).getAllNodesWithLabel(Labels.User).iterator();
while (iterator1.hasNext()) {
Node result = iterator1.next();
UserDao.printoutNode(emailAddress, result);
}
And UserDao.printoutNode
public static void printoutNode(String emailAddress, Node next) {
System.out.print(next);
ResourceIterator<Label> iterator1 = next.getLabels().iterator();
System.out.print("(");
while (iterator1.hasNext()) {
System.out.print(iterator1.next().name());
}
System.out.print("): ");
for(String key : next.getPropertyKeys()) {
System.out.print(key + ": " + next.getProperty(key).toString() + "; ");
if(emailAddress.equals( next.getProperty(key).toString())) {
System.out.print("MATCH!!!!!!!!!");
}
}
System.out.println();
}
I already debugged through the code and what I already found out is that I pass via the InternalAbstractGraphDatabase.map2Nodes to a DelegatingIndexProxy.getDelegate and end up in IndexReader.Empty class which returns the IteratorUtil.EMPTY_ITERATOR thus getting false for iterator.hasNext()
Any idea's what I am doing wrong?
Found it:
I only included neo4j-kernel:2.0.0-M03 in the classpath. The moment I added neo4j-cypher:2.0.0-M03 all was working well.
Hope this answer helps save some time for other users.
#Neo4j: would be nice if an exception would be thrown instead of just returning nothing.
#Ricardo: I wanted to but I was not allowed yet as my reputation wasn't good enough as a new SO user.