Hi I'm working on an Android app and I need to use GraphQL. I'm trying to use the Apollo client first by following this tutorial as practice but am having trouble following it through. It just lacks some specific information and details that would be helpful.
Currently what I'm stuck at is trying to construct a .graphql file. I was hoping to at least compile the code and make sure everything up to this point was fine, but apparently you can't even compile it without providing at least one .graphql file.
I've included the example given in the tutorial below, my confusion mainly comes from what exactly is "FeedQuery" and "FeedType"? Are they classes defined for this particular example or are they classes generated by Apollo itself to define any query? So should I just use those two classes when defining my own queries or make equivalents? And are those parameters also something required in the defintion or something specific to the examples strucutre?
I can't seem to find more information about this in their tutorial or website. It's tough enough trying to learn GraphQL but the lack of details in this tutorial is making things a lot more frustrating. If they had shared what the structure looks like in this tutorial it would have been really helpful but it doesn't seem to be included.
query FeedQuery($type: FeedType!, $limit: Int!) {
feedEntries: feed(type: $type, limit: $limit) {
id
repository {
name
}
postedBy {
login
}
}
}
Thank you for your help, and if anyone has a link to a better tutorial I'd really appreciate it.
I the context of the GraphQL DSL, FeedQuery is a named query (think of it as a method in Java terms) that you can use to retrieve specific data (as described by the internals of the query) from a GraphQL server.
To retrieve the desired data, you need to pass in two non-null arguments (denoted by the !), the feedType and the limit. The first is a custom type defined by the GraphQL schema implemented by the server. The second is a GraphQL scalar type.
Both the FeedQuery and FeedType will be converted to Java objects during compilation phase. For queries, you will be provided with an appropriate builder to include all the necessary information to perform the actual call.
You can read a complete Java example here. It is a more complete version of the tutorial you are following.
Related
I have a SOAP Web Service that i want to parse and use in my android project. I have read that there is a website that auto generates the java classes by importing the url (wsl2code) but it seems to have flaws. Additionally the sample they provide is not working. What is the best and correct way of generating java classes from a WSDL url for my android project?
Use ksoal2 library for soap service which is light weight for android but the think you have to create service call manually
To answer my own question, I have used the service of wsdl2code http://www.wsdl2code.com/pages/home.aspx . Just some information regarding that, it has some limitations like
Don't Support byref Variables , in class
Don't Support Boolean& Variables , in class
Don't Support Int64& Variables , in class
Methods that are boolean or a custom class are turned to void and must be modified manually
Overall though this website saved me since it would take me a while to create the classes I needed by myself. It might have taken me a while to modify the classes but still saved a lot of time.
I'm creating an Android application which uses RoboSpice for asynchronous network calls. Although I have no experience with RoboSpice, I've chosen for RoboSpice as it's regarded as one of the best on the internet, and because it can automatically convert JSON to POJO's. Unfortunately, the quality of the documentation of RoboSpice is a bit poor. Therefore my question:
I've succesfully used RoboSpice to make a network call to a REST GET method, automatically parse the JSON to a POJO and show the list of retrieved objects in an Android ViewPager. I'm using Jackson2GoogleHttpClientSpiceService to do this. Now, in this ViewPager I'm showing an image as well. Obviously, I want to download this image using RoboSpice. I've used one of the RoboSpice examples (which uses the OkHttpBitmapSpiceManager to download an image) as a guide and according to that I've added this line to my activity:
private OkHttpBitmapSpiceManager spiceManagerBinary = new OkHttpBitmapSpiceManager();
Also, I've added this line to the manifest:
<service
android:name="com.octo.android.robospice.spicelist.okhttp.OkHttpBitmapSpiceService"
android:exported="false" />
Now, as I'm not using maven for my Android project, I had to add the following jar to my project: robospice-ui-spicelist-1.4.9.jar (I've obviously added all the other necessary jar's for using the Jackson2GoogleHttpClientSpiceService, which works).
The problem is, the application fails to even start. Whenever I remove (or comment) the line containing the new OkHttpBitmapSpiceManager() the application works flawlessly. So apparently calling the constructor is what makes the application crash. I get the following error from the logcat:
java.lang.NoClassDefFoundError: com.octo.android.robospice.spicelist.okhttp.OkHttpBitmapSpiceService
To me, this error seems to relate to a missing jar or something. But I've added all the necessary jar's according to the documentation. Can someone with experience of RoboSpice explain to me what I'm doing wrong here? Should I add more jar's or am I missing something else? Or should I even use a completely different approach to loading images from a URL using RoboSpice?
EDIT!
To make it more clear, I've added the following jar's to my libs folder and the build path:
commons-io-1.3.2.jar
commons-lang3-3.1.jar
google-http-client-1.17.0-rc.jar
google-http-client-android-1.17.0-rc.jar
google-http-client-jackson2-1.17.0-rc.jar
guava-jdk5-13.0.jar
jackson-core-2.1.3.jar
jsr305-1.3.9.jar
robospice-1.4.9.jar
robospice-cache-1.4.9.jar
robospice-google-http-client-1.4.9.jar
robospice-ui-spicelist-1.4.9.jar
The problem is that you are not using a jar that contains the service class : com.octo.android.robospice.spicelist.okhttp.OkHttpBitmapSpiceService.
It is not contained in robospice-ui-spice-list but in robospice-okhttp. If you include this jar, you will get the service you need.
Have a look at this sample.
Also, please not that to download an image, it can be even easier to use non okhttp related classes. RS offers simple binary requests in its core package.
Oh, and btw, when you say "RS docs is a bit poor", please let us now via github or the mailing list how you would like to see it more complete. We also accept pull requests, even only for documentation.
In my Android app, I need to talk to a webserver that expects marshalled objects of complex classes. These custom classes were produces from a WSDL file, so they already come with annotations. The server uses JAXB for marhalling and unmarhalling.
So, on the client side, using JAXB, I would simple to this:
JAXBContext jc = JAXBContext.newInstance("schema_definition_path");
Marshaller m = jc.createMarshaller();
Unmarshaller u = jc.createUnmarshaller();
...and then use the Marshaller and Unmarshaller instances to work serialize/deserialize the custom objects.
Since, it's not a great idea to use the heavy-weight JAXB lib in mobile apps, I am looking for an alternative to do what JAXB does for me here.
I checked out Simple XML Serialization, but that doesn't seem to provide this kind of functionality. I can only give a class to the unmarshaller instead of the schema definition path. Doing this results in an incomplete xml document, containing only the root element.
Can anyone point me in the right direction, please? Is this even possible? Should I use a different lib - which one? I am I just misusing SimpleXML?
Since I couldn't find any better way (see comments to the original question), I decided to manually convert the Objects using the XML Pull API implementation included in Android.
Here is a short tutorial on how to use it: http://www.ibm.com/developerworks/opensource/library/x-android/
I'm not saying it's a good way, but it's the only thing I can think of that will work and where I don't have to touch the original classes.
I have a custom ContentProvider class, which I originally developed in the same project file with the application using it. However since this application is intended to be only one of many users of the ContentProvider, I want to split it in a different project. The code is being developed on the Android PDK, but future clients might be developed on the SDK (on a custom SDK, or SDK plugin, etc).
The problem I'm facing, is about the constants in the ContentProvider class, e.g. CONTENT_URI, column names and as well some constants which are used to interpret the values returned from queries. These of course cannot be accessed from another project. It seems to me I have 3 options at this point:
1) Ignore the problem, and type in the values directly in the user application code. This however makes accessing the ContentProvider uglier. I would have to change some columns, to encode some columns with strings instead of integers, to keep the code maintainable.
2) Put the constants in a separate class, and include a full copy in applications using the ContentProvider. I'm not a fan of duplicating code though. Keeping a duplicate of this code in each target app, will make some things slightly more annoying to maintain.
3) Abuse the fact that I'm developing on the PDK, and expose a platform library, as described in vendor/sample/frameworks/PlatformLibrary. However, platform libraries don't have a manifest file, which if my understanding is correct means that I can't include a ContentProvider. This means I would need one "normal" project for the ContactProvider, and a separate one just to expose the class with the constant values. This feels so much wrong.
The answer at Class structure for a ContentProvider having multiple sub tables seems to imply option (1), which probably looks like the best option right now.
However, maybe I have missed another, neat & tidy, way to do this? Keeping in mind that I am developing on the PDK, I would certainly like my ContentProvider to be usable in the same manner as stock Google providers.
You probably already have at least one class/interface that defines the "contract" of your ContentProvider using static constants for column names, a content URI, etc.
If you put this into its own Android SDK library project (just for the Android classes to be on the build/classpath), you can then use this library from your actual SDK/PDK application's ContentProvider and also distribute it as myapp-api.jar JAR for others to use.
This way you get the best of both worlds: No outdated code (because your ContentProvider depends on it) and other people can use nice constants for URIs and column names.
For an example of a contract class, see ContactsContract.
A REST XML (not JSON!) Web Service should exchange XML Schema specified XML between a Google App Engine and an Android app.
I wanted to use XStream for both, however, I could not get it to work for the Google App Engine, therefore to me Apache XMLBeans is the next best choice (JAXB does not work on both).
However, with Google App Engine there is no problem, but on Android, I get several severe exceptions (eg. due to the usage of the Stax API with its javax.xml.* packages).
So,
Is there any other XML-binding possibility to stream XML documents on GAE and Android?
If not, is it possible to patch Apache XMLBeans to work with Android?
Thanks!
I'm poking in the dark here, since i haven't tried anything of this, yet:
There's this blog entry from XBinder which claims that they are releasing an android-compatible version "in a few weeks". While that might not be an option right now, they also explain a bit of how they have done it, wrapping a light StAX-like wrapper on the XmlPull support already present in Android.
(my answer originally had another paragraph on XStream working on android, but then i read the question again and saw that your problem was with getting XStream to work on the AppEngine side...)
An XML data binding framework that works on both Google App Engine and Android is Simple. It uses annotations similar to JAXB to annotate a POJO which can then be serialized and deserialized in XML. For example, an annotated object would look like.
#Root
public class Pojo {
#Attribute
private String name;
#Element
private String value
public String getName() {
return name;
}
public String getValue() {
return value;
}
}
Then to generate XML all you have to do is.
Serializer serializer = new Persister();
serializer.write(instance, outputSteam)
To read you can do
Serializer serializer = new Persister();
Pojo pojo = serializer.read(Pojo.class, inputSteam)
And thats it! Its quite a powerful framework with many other features and annotations. It works for Android, Google App Engine, and any JDK 1.5+. It has no dependencies and is very light weight. For more information see the Tutorial.
Another option is Pulloid (pulloid.org). It relies on the XmlPull API which is included in Android. On the App Engine side you would need to use an XmlPull implementation such as XPP3 for now - I don't know if it's a show stopper or not.
Android lacks built-in support for XML generation, period. Android is stronger with JSON, since it can both parse and generate JSON documents.
In terms of patching XMLBeans, you may find it quicker to find some other package that has fewer dependencies. You cannot readily import any new code that resides in the java.* or javax.* packages.
You can use Castor . Just be sure, in Android 2.1, not to use default android SAXParser. You'll get namespace errors. You do this by defining the parser to be, for example, Xerces (and the you add the required JARS), in core.properties . In android 2.2 it may be ok. Note that if you create an xmlcontext for the unmarsheler with xerces, it still won't work, as the mapping itself would be parsed with android's SAX. It must be done at core (top level properties file) so that even the mapping is parsed by xerces. finally - performance is as slow as you can expect... :( Good luck SM