I am doing a demo project on graphql queries. Followed all the required steps and downloaded schema.json from my dummy graphql server on graphcool. However when I am writing the .graphql file which contains the graphql queries, android studio is showing me errors for the fields. Even after I have successfully built the project, still the errors persist. I have a dummy graphql server which has type Employee and 5 fields : name,id,height,age and work.
I have tried making a new project and re writing all the code. I have tried rebuilding and cleaning my project, etc,. I have re downloaded the schema.json file and tried deleting and rewriting the .graphql file. Yet the errors are still thrown.
query getAllEmployeeDetails{
allEmployees{
name
id
height
age
work
}
}
this is my .graphql file. Android studio throws errors on all the 5 fields and also throws error on the "allEmployees" too.
The corresponding query on graphql backend is:
query{
allEmployees{
name
id
height
age
work
}
}
which works fine.
Expected result is that android studio shouldn't be throwing an error on the fields.
I have faced the same error you have mentioned in the comment, the whole queries show the same error every field couldn't be resolved but in development the code works fine.
So I searched many times until I found this issue
After opening the .graphqlconfig file there is a button to run a query called "introspection query" here like this snapshot here
A new file will be added automatically to your graphql folder called "schema.graphql", It is a file contains the whole inputs, types & scalars by the end-point, after generating the file, everything will be normal again and the errors will be vanished.
Add a file named .graphqlconfig to the root of your project. The file's content should be something like this:
{
"name": "Remote Schema",
"schemaPath": "remote-schema.graphql",
"extensions": {
"endpoints": {
"Apollo Fullstack Tutorial": {
"url": "https://apollo-fullstack-tutorial.herokuapp.com/",
"headers": {
"user-agent": "JS GraphQL"
},
"introspect": true
}
}
}
}
Change the url to your server's endpoint and change "Remote SWAPI GraphQL Endpoint" to better describe your server.
Also, see here
I had this same issue...
Zizoh and Mahmoud Magdy explained it but ill leave it here with more details to help anyone who needs..
In android studio, in root folder create a .graphqlconfig like this :
change that URL for your server url
]2
after that, click on the play icon in the config file you just created..
]3
And now everything should be working as you would like :)
Related
I'm working on Ionic mobile app development.
My requirement is to create client side logger to track issues in app. I used the methods mentioned in https://github.com/pbakondy/filelogger, and I could able to create the log file in both Android and iOS.
For the first time when I open the app, it creates the log file in cordova.file.dataDirectory, when I close and reopen the app in i*OS, I'm trying to read the content of the file which was created using the below
$fileLogger.getLogfile().then(function (loggerContent) {
var temp =loggerContent;
});
But the application says
{
"applicationDirectory":null,
"applicationStorageDirectory":null,
"dataDirectory":null,
"cacheDirectory":null,
"externalApplicationStorageDirectory":null,
"externalDataDirectory":null,
"externalCacheDirectory":null,
"externalRootDirectory":null,
"tempDirectory":null,
"syncedDataDirectory":null,
"documentsDirectory":null,
"sharedDirectory":null
}
So I couldn't able to find the file where i saved my logs.
Please help me resolve this issue or if you could recommend me a different method to get around this issue, that would be great!
Thanks for the answers
There is a check list here and should solve your problem :
1-Be sure that the cordova-file-plugin is installed and works in your test environment.
2-Be sure that the cordova.js file is refrenced by your html and before your code usage.
3-Be sure to call your codes after device_ready state :
check this
4-Call your function after a short delay (use setTimeOut in Javascirpt)
Ali's item 4 is very important:
I had a similiar problem on different platforms: cordova.file.dataDirectory was null.
I tracked cordova.file.dataDirectory over the lifecycle and it was first accessed by my Ionic 2 code BEFORE the device ready event was fired.
My "mistake": I wanted to load data during the constructor(!) of a service. Seems too early.
My code used to work, it does not work anymore, I tried troubleshooting and can't figure out why.
I have this piece of code in my PHP:
$android_id_01 = $_GET['pmysql_room_id'];
$android_id_02 = "";
$f = fopen("00_android_id_01.txt", "w");
fwrite($f, print_r($android_id_01, true));
fclose($f);
$f = fopen("00_android_id_02.txt", "w");
fwrite($f, print_r($android_id_02, true));
fclose($f);
For troubleshooting I created two android IDs ($android_id_01 and $android_id_02) which are both empty (The first one is From Android and the second one I created directly from PHP).
Now when I launch my Android device, the PHP file is executed from server side and both the text files are created empty and identical. Now my code only works when I use $android_id_02 and not $android_id_01 from the code below:
if ($android_id == '')
{
//my code
}
(Yes when I use either one of the $android_id_01 OR $android_id_02 I rename it to $android_id and comment out the other one)
My question is, although this was working yesterday, why does it work with $android_id_02 = ""; and not $android_id_01 = $_GET['pmysql_room_id']; even though they are both empty????
I don't know what changed from yesterday to today.
Ok after a bit of troubleshooting I found a solution, strange though.
On the server side "display_errors" under PHP settings must be turned off. Somehow having this on interferes with the json_encode sent back to android client. (even though my code is not generating any errors)
Anybody success to use the plugin cordovaFile & cordovaFileTransfer?
I have failed to understand and failed miserably execution. Case wants to make the upload and download controller. Each tested via the browser, it always appears File / FileTransfer is not defined in Firebug. When I made to console.log as:
console.log($cordovaFile); or
console.log($cordovaFileTransfer); or
console.log($cordovaFileTransfer.download); or
console.log($cordovaFileTransfer.upload);
Its return true, form of the {object}.
But when I call their methods included parameters, for example:
$cordovaFileTransfer.download (urlServer, fileTarget, {}, true);
Direct emerge error: FileTransfer is not defined.
I tried to move the download function to the Service, and then Controller call the function (the umpteenth time search results on google). The result is just the same, the above error.
Because there are user in some forum said should / could only be tested through the device, finally I try to upload ionic.io & I sync via APL ionic view on my Smartphone. But the result is NOTHING.
I tried to improvise a little, try method checkDir / checkFile as follows:
.controller('PhotoCtrl', function($scope, $cordovaFile) {
$scope.downpic = function(){
$cordovaFile.checkDir("/sdcard/storage/emulated/0/").then(function(result){
alert("wow");
}, function(err){
alert("eror");
});
}
})
It turns out alerts that appear "error", I try mutually value directory is as follows:
file///sdcard/storage/emulated/0/
file///storage/emulated/0/
/storage/emulated/0/
Just the same error alerts, the chain problem. My question :
What is the application of ionic cordova can access the internal
storage? (I only have the Mobile Internal Storage, without External
Storage);
I was looking for information about AndroidManifest.xml
uses-permission, the permission is only for external storage. Are
there any other analysis?
Please help, really newbie
Finally, I just got the clear solution from the link below :
https://www.thepolyglotdeveloper.com/2014/09/manage-files-in-android-and-ios-using-ionicframework/
I am using Jenkins to test, build and release an Android project. Jenkins puts the generated .apk file into an s3 bucket like so:
s3cmd put example_app/bin/example_app.apk s3://preview.example.com/android/example.apk;
s3cmd setacl --acl-public s3://preview.example.com/android/example.apk;
The .apk in this bucket can then be accessed and downloaded by the public when visiting preview.example.com
The issue I am running into is that I also want to pass along the timestamp of when Jenkins built the example_app android project so that this time/date can be displayed on the preview.example.com page as well. Is there a good way to do this?
I found a solution, but it does not seem ideal...
Jenkins has an environment variable called BUILD_ID which is:
The current build id, such as "2005-08-22_23-59-59" (YYYY-MM-DD_hh-mm-ss)
In the Jenkins build I created a text file to contain this date string and put it in an s3 bucket:
touch timestamp.txt
echo ${BUILD_ID} > timestamp.txt
s3cmd put ./timestamp.txt s3://preview.example.com/android/timestamp.txt;
s3cmd setacl --acl-public s3://preview.example.com/android/timestamp.txt;
Then when rendering the webpage I use ajax to access, manipulate and display this date like so:
$.ajax({
type: "GET",
url: "http://preview.example.com/android/timestamp.txt",
dataType: "text",
success: function(data) {
var timestamp = data.replace(/(\d{4})-(\d{2})-(\d{2})_(\d{2})-(\d{2})-(\d{2})/," $2-$3-$1 $4:$5:$6");
$("div.timestamp-unstable-android").append("Updated: "+timestamp);
}
});
Which displays a date that looks like this: Updated: 07-10-2014 17:29:38
So this works... however there is still the problem that this is UTC time, not local
I'm implementing schema validation using libxml2. The schema I'm validating against imports two other schemas with lines like:
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="http://www.somewebsite.com/xsd/xml.xsd"/>
All three schema files are located in the same directory on the device.
This works well when the device has internet access, but fails when it does not, as libxml2 still attempts to download the imported schemas from the schemaLocation even though I'm passing in XML_PARSE_NONET.
I tried getting libxml2 to load the files locally by editing the schemaLocation attribute to xml.xsd, ./xml.xsd, and file:///data/data/com.company.appname/files/xml.xsd, but all three resulted in the same libxml2 error:
domain: 16
code: 3069 (XML_SCHEMAP_INTERNAL)
message: Internal error: xmlSchemaParse, An internal error occurred.
I also tried removing the schemaLocation attribute entirely, on the off-chance that libxml2 might search for the imported schemas alongside the original schema, but that resulted in the following error when the schema parser hit a line that referenced the imported entities:
<xs:attribute ref="xml:lang" use="required"/>
domain: 16
code: 3004 (XML_SCHEMAP_SRC_RESOLVE)
message: attribute use (unknown), attribute 'ref': The QName value '{http://www.w3.org/XML/1998/namespace}lang' does not resolve to a(n) attribute declaration.
I also looked into manually merging the three schemas into a single file, but as they use different namespaces, this is not possible.
The standard solution for this seems to be the XML catalog, but I've read through libxml2's catalog documentation, and I can't figure out how (or even whether it's possible) to add mappings that will be used by my app when deployed to a device. I think I might need to implement an xmlExternalEntityLoader, but the documentation for that is quite slim.
How can I get libxml2 to import these schemas without network access? Obviously I'd ideally like a robust solution that works with the unedited schema, but I've be content with something quick-and-dirty that involves editing the schema, like my original attempts described above.
The errors described above are from an Android device (using JNI), but I'm having similar problems on iOS, where the solution will also need to work.
One way to do this is to intercept libxml2's call to open the imported URL with a custom xmlExternalEntityLoader.
The basic code for doing this is as follows:
#include <libxml/xmlIO.h>
#include <libxml/parserinternals.h>
xmlExternalEntityLoader defaultLoader = NULL;
xmlParserInputPtr
xmlMyExternalEntityLoader(const char *URL, const char *ID,
xmlParserCtxtPtr ctxt) {
xmlParserInputPtr ret;
const char *fileID = NULL;
/* lookup for the fileID
* The documentation suggests using the ID, but for me this was
* always NULL so I had to lookup by URL instead.
*/
ret = xmlNewInputFromFile(ctxt, fileID);
if (ret != NULL)
return(ret);
if (defaultLoader != NULL)
ret = defaultLoader(URL, ID, ctxt);
return(ret);
}
int main(..) {
...
/*
* Install our own entity loader
*/
defaultLoader = xmlGetExternalEntityLoader();
xmlSetExternalEntityLoader(xmlMyExternalEntityLoader);
...
}
(Slightly adjusted from the sample code in The entities loader section of libxml2's I/O Interfaces documentation.)