GraphQL Elixir/Phoenix API: Socket hang up with large json response - graphql

New to Elixir/Phoenix and GraphQL. I have created a simple API that retrieves "drawings" from a PostgreSQL database. The table consists of an "id" (uuid) and "drawing_json" (text). In the table is one row with a json string of about 77Kb. My schema and queries are defined using Absinthe. I have 1 query called "all_drawings" which resolves and reaches out to the Repo and pulls in all drawings. When using postman to call this API, the following query works fine:
{
allDrawings
{
id
}
}
However, when I try to return the json field as well the postman request times out and I get a "socket hang up" error.
Looking at the Debug Console in Visual Studio Code, I can see the query gets the data from the db just fine and almost immediately. Something seems to be happening though in returning it to the client that I can't detect. No errors are thrown. Any ideas? Not sure what information will help but happy to provide more.

A colleague helped me find the fix. Not sure why this is (maybe someone can elaborate), but the issue was with trying to run it in Visual Studio Code. Previously, I set up the run task in launch.json and would click the run button to start debugging my application. This would cause the aforementioned crash every time. When I went to the terminal and ran the "mix phx.server" command, everything worked fine. Not sure if the hang up is with Visual Studio Code or the ElixirLS extension when using the IDE to debug. But starting the application through the command line allowed me to use postman to hit the api and retrieve the data just fine. I'm very new to the Elixir/Phoenix world so I'm unable to draw a more intelligent conclusion as to why this happens.

Related

Apollo cache is getting reset back to old data

I'm building an Expo mobile app using AWS AppSync and Apollo and I've got an intermittent but very serious issue with the cache getting corrupted, or at least not being updated properly. Unfortunately, because I'm using AppSync and I want the offline capability, I can't upgrade to the latest Apollo client, so as a result the data is stored in Redux, there are 4 top-level keys: offline, rehydrated, appsync and appsync-metadata.
This is what I expect to happen:
GraphQL query for a "project" returns the correct data
This data is written into the cache. In particular, I'm expecting that in appsync.ROOT_QUERY there'll be an entry for the project, something like getProject({"input":{"id":"project-7"}}) plus a top level entry in appsync for the project with all of its properties.
When I do execute a mutation, I'm expecting the project entry to be updated.
Since the project is updated, I'm expecting the UI to be refreshed reflecting the updated data.
Most of the time, this happens exactly as above. However, sometimes something happens to the cache. I'm not sure exactly what, but it gets into a weird state and I can't fix it.
Here are the symptoms:
When I start the app, the cache is initialised to an "old" state, one that doesn't include the query for project-7 even though I had queried for it just moments before killing the app.
When I do a search for project-7, it then adds the getProject...project-7 query to the cache and an entry for project-7, but for some reason doesn't seem to have all the fields.
When I do a mutation, there's an AAS_WRITE_CACHE which actually removes the getProject...project-7 entry from the query cache! The mutation succeeds though, I can see that the data in the AppSync server is updated, and the client doesn't log any errors anywhere.
The UI does NOT update.
I tried adding an update to the mutation so that I could update the cache myself, but when I execute const data = proxy.readQuery({ query: ProjectQuery } ... ) (specifying project-7), it throws an exception to say that it can't find that query, so I can't update the project. If I manually re-get the project, then everything works again until the next mutation.
What's really difficult, is that once my app is in this state, I can't work out how to fix it. I've tried client.resetStore() but it just gets rehydrated. I've tried calling AsyncStorage.clear() and then stopping the app and restarting it, but that doesn't work either. How can this be? Where is it storing the data?
It's worth saying again that on most of the devices I've tested it on (both Android and iOS), it works for days without any problems, but on one Android device in particular, it happens once every day or two. Twice I've been able to fix it using the "Clear Async storage" in the React Native Debugger, but now even that doesn't seem to fix it.
So, here are my questions:
Can anyone suggest what might be causing the cache to get into this weird state? Or how I can try and track down the problem.
Where is it storing the data that it then puts back? There are snapshots of the cache in appsync-metadata but surely they should also be removed when I clear all the AsyncStorage?
I'm really stuck!!
PS Here are the relevant (I think) packages I'm using:
"apollo-client": "^2.5.1",
"aws-amplify": "^1.1.27",
"aws-amplify-react-native": "^2.1.11",
"aws-appsync": "^1.7.2",
"aws-appsync-react": "^1.2.7",
"expo": "^33.0.0",
"graphql": "^14.3.0",
"graphql-tag": "^2.10.1",
"react": "16.8.3",
"react-apollo": "^2.5.8",

If session cookie not exists CodeIgniter return error on model query

I have a CI application that works in the Browser and ElectronJS, I am using FPDF to generate some reports, but I have a problem when a I need to open the PDF from ElectronJS to Internet Explorer or Chrome. If I launch PDF link from Electron I get and syntax error on model query. But if I login using the browser and relaunch the PDF everything works well, It looks like the problem is the session that not exists in browser... but I don't have idea how to solve this problem. Can someone help me?
Electron app
Browser error after launch the PDF from Electron
Sorry for my English, regards...
You're not showing any code, but a simple inspection to your DB error shows what the problem is:
where a.codigolocal= and adddate(...)
See how the a.codigolocal= constraint doesn't have anything after the = sign and goes straight to the next and clause?
This is very likely because what you are passing as an argument to that constraint comes from the session cookie. No cookie, null value, syntax error.
You need to make sure you have all the data you need (either by checking there's an active session before running the query, or by making sure your query doesn't depend on a session variable that may or may not be there)

After upgrade from Dynamics CRM 2011 to CRm 2016 experiencing weird issue with forms and plugins

Client company just upgraded to 2016 from 2011. I've been testing the plugins to make sure they all still function and I've finally (after much frustration) figured out what is happening, but no idea why or how to resolve this.
I have several plugins and they all function exactly as expected - as long as the updates to the data are not run through the forms.
Let me explain:
I have plugins (Synchronous) that trigger on a change to a field. If the field is changed via a workflow, or some other coded process, everything runs just fine.
But when I update the field on the form it's self. It fails with a very generic error (below).
I support a couple of other clients already on 2016, and I'm not experiencing this same problem. So I'm not even sure where to begin. I've been going crazy here the last couple of days to check the code. But it only happens when updating the field on the form. Every other method of updating the data that I have tested works with no errors.
I also have another issue. When the field is updated (through a test workflow), it runs and updates a child record. The child record then has a workflow that runs to deactivate the record. The workflow says it ran and deactivated the record, but it never deactivates).
Anyway. if ANYONE has ANY idea at all about what could be causing this. I would love to hear it. I'm at my wits end on this.
Thank you in advance.
I've tested the code and had it run successfully, as long as I don't update the field through the form. To test this I created some test workflows that update the data, they successfully run and the plugins fire off with no problems.
EntityReference contact =
(EntityReference)preImageEntity.Attributes["ipmahr_contact"];
QueryExpression cn = new QueryExpression("ipmahr_recertification");
cn.ColumnSet = new ColumnSet("ipmahr_contact", "statecode");
cn.Criteria.AddCondition("ipmahr_contact", ConditionOperator.Equal,
contact.Id);
cn.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);
EntityCollection results1 = server.RetrieveMultiple(cn);
if (results1.Entities.Count > 0)
foreach (Entity a in results1.Entities)
{
a.Attributes["ipmahr_deactivaterecertificationrecord"] = true;
server.Update(a);
}
The code is pretty straightforward in most cases, and works fine as long as things aren't updated on the form.
Here is the error: Exception: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: System.ServiceModel.CommunicationObjectFaultedException: #595EB751 (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault)., Correlation Id: fd1a79ca-c846-407b-b578-ac9207d6dd0e, Initiating User: 274d55dc-3f4d-e811-b30f-0050569142af Exiting Recertifications.Main.DeactivateUsedRecertificationsonEndDateChange.Execute(), Correlation Id: fd1a79ca-c846-407b-b578-ac9207d6dd0e, Initiating User: 274d55dc-3f4d-e811-b30f-0050569142af
New information. I have found that not all the plugins I've written have an issue on this server. This is good. But I also found that there is a commonality on those plugins that do fail.
Any plugin using a Query Expression fails with the generic error. Adding robust error checking didn't show anything (once error checking was added, it just didn't run anything, and didn't produce any errors in the logs). Trace logs didn't show anything significant either.
So now I'm wondering if there is something in the way the Query Expression is formatted, or if there is an issue with the SQL. I mention SQL because I found this morning that if I create fields too fast, I get a generic SQL error. Wait a minute and I can create new fields without a problem.
I think it likely that this plugin is not actually failing based on the error you are receiving and the fact that it happens conditionally. More likely, your server.Update(a); call is resulting in a failure within a secondary plugin or workflow action triggered by update of the Recertification record.
- Comment out that line and verify that the plugin works
- See if you can reproduce a failure by directly updating that field on the Recertification record
- Review plugin/workflows running against the Recertification entity
Most likely this has one of the following root causes:
- A security issue based on different executing users between the form update or workflow update
- Other tangential fields are being updated by one or the other of those two methods which subsequently cause different behavior in a secondary plugin/workflow

Cant figure out, why i get a 403

i try to setup the youtube api but i get a 403.
I tried to setup several times- without success.
https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id=-DIJvggBrg8&key=xyz
Maybe someone is able to help me or even login to the console for a setup?
The 403 error by itself is not of immediate use. Its attached error code (as I already pointed out above) sheds light on the things that happened.
The API responds to any query you make with a text (that is structured in JSON format). That response text contains the needed error code.
I suggest you to proceed with the following steps:
delete the old API key (right now it is still accessible!);
create a new API key and
run your API query using the new key and then post here the API response text.
Note that I checked the video -DIJvggBrg8 to which your query refers to with my own API key and got no error but a JSON text describing the video.

Entity Framework 'add/update' error on server only

I'm running into a problem that only seems to affect an application when its been deployed.
Here are the details:
- Application developed in Visual Studio 2010, using MVC 4 (using Razor) and Entity Framework
- Application is going against a database running Oracle 11g
- We've got some developers using XP and others using Win7.
- The application was bin-deployed to a server running WindowsServer 2008
The application has the following functionality:
try
{
COMMENT_TABLE comment = new COMMENT_TABLE();
comment.comment_id = id_val;
comment.comment_text = fc["txtcomments"];
db.COMMENT_TABLE.Add(comment);
db.SaveChanges();
return RedirectToAction("Det", new { id = evalid });
}
catch (Exception ex)
{
return Content(ex.Message);
}
In our development environment under Visual Studio, this works perfectly. However, when we deploy it to our web server, we get the following error:
"An error occurred while updating the entries. See the inner exception for details".
However, other parts of our code (where we do searches and retrieve records, or where records are updated) have no problem, so at least some database access works. Its just when we try to do the above update that the error occurs.
I found a couple of references, to this, but they all seem to be dealing with retrieving the error through Visual Studio (which, of course, doesn't help because it works in development.)
Any idea what the issue could be?
Ok, my apologies... I think I found the problem.
I had some problems getting the inner exception working (didn't realize I had to call 'GetBaseException'), but once I did I noticed something...
The 'comment_text' field was set to non-null in the database... in another part of the code, the comment text was getting populated by user.identity.name (i.e. the person logged in).
In Visual Studio, user.identity.name was set to the user login. However, on the web server it was null. So, the field wasn't set properly.
Now I feel a bit foolish. Sorry to have wasted everyone's time.

Resources