How to set up demo client for graph-ql integration in flutter - flutter

I don't know much about graph-ql and need a demo setup that could run.
I am stuck and don't know how to setup client,
Can anybody could explain me how to setup client in this given code:-
https://github.com/zino-app/graphql-flutter/blob/master/example/lib/main.dart
Client(
endPoint: 'https://api.github.com/graphql',
cache: InMemoryCache(),
apiToken: '<YOUR_GITHUB_PERSONAL_ACCESS_TOKEN>',
),
also what is ReadRepositories in
String readRepositories = """
query ReadRepositories {
viewer {
repositories(last: 50) {
nodes {
id
name
viewerHasStarred
}
}
}
}
"""
.replaceAll('\n', ' ');

Related

Issues in Offline synchronization of JSONStore with Cloudant DB

Whenever any json is entered in JSONStore it wraps the input like below: {"json":{JSON_INPUT},"_id":1}. Now if I change the id to string and try to push it to cloudant it successfully pushes it. But this is not the correct way as it will have the wrapper in it and when you will try to sync it next time with the JSONStore it will add another similar wrapper which will break your HTML pages. Now what i tried is by going one level down (var str=dirtyDocuments[i].json) and send the input(str) only, it gives the below error everytime:
[ERROR ] FWLST0105E: can upload user log file due to java.io.IOException: Unexpected character '\u0000' on line 1, column 2784.
Below is the code to sync the data back to cloudant DB:
pushToAdapter(){
let collectionName = 'activities';
let options = {};
WL.JSONStore.get(collectionName).getAllDirty(options)
.then(function (dirtyDocuments) {
for(var i=0; i < dirtyDocuments.length ; i++){
var id = dirtyDocuments[i]._id;
dirtyDocuments[i]._id=id.toString();}
var resource = new WLResourceRequest("/adapters/ServiceAdapter/pushActivities", WLResourceRequest.GET)
resource.setQueryParameter('params', dirtyDocuments)
resource.send().then((success) => {
console.log('-->JSONStore : Push document success', success)
}, (failure) => {
console.log('-->JSONStore: Push document failed', failure)
})
})
}
Adapter Method:
function pushActivities(dirtyDocs) {
var path = 'employees';
var input = {
method : 'post',
returnedContentType : 'json',
path : path,
body: {
content: JSON.stringify(dirtyDocs),
contentType: 'application/json'
}
};
return MFP.Server.invokeHttp(input);
}
Please let me know if i can help with any other input.
NOTE: I have confirmed this by giving a sample input like this:
{"name":"abc"}. But it was same, so i can ensure there was no such characters in my json input.
EDIT:
pushToAdapter(){
let collectionName = 'activities';
let options = {};
WL.JSONStore.get(collectionName).getAllDirty(options).then(function (dirtyDocs) {
for(var i=0;i<dirtyDocs.length;i++){
var id=dirtyDocs[i]._id;
id=id.toString();
dirtyDocs[i]._id=id;
}
WL.Client.invokeProcedure({
adapter : 'ServiceAdapter',
procedure : 'pushActivities',
parameters : dirtyDocs // If i use say dirtyDocs[0].json it fails.
}).then(
(success)=>{console.log('success',success)},
(failure)=>{console.log('failure',failure)})}).then(function (responseFromAdapter) {
})
}
Below is the updated pushToAdapter() method that worked for me.
pushToAdapter(){
console.log("Inside push to adapter");
let collectionName = 'activities';
let options = {};
WL.JSONStore.get(collectionName).getAllDirty(options).then(function (dirtyDocs) {
var temp=[dirtyDocs[0].json]; //Here its only for one element.
WL.Client.invokeProcedure({
adapter : 'FieldsServiceAdapter',
procedure : 'pushActivities',
parameters : temp
}).then(
(success)=>{console.log('success',success)},
(failure)=>{console.log('failure',failure)})}).then(function (responseFromAdapter) {
console.log('Response from adapter',responseFromAdapter)
})
}
So the change is basically it expects an array, and I was just sending a JSON string. May be a very silly mistake to commit.
NOTE: The error mentioned above had nothing to do with this, this was a parsing error which i found out later. The above error may be because of some log files that could not be uploaded to the server.

Webdriver.io - visual regression Service compare not recognized with multi remote

I got visual regression working in webdriver.io and it is very wonderful. I would, however, like to also use it with multi remote. When I add the necessary configuration to my wdio.conf.js file for multiremote, I get the following error
Error: Please provide a visualRegression configuration with a compare method in your wdio-conf.js!
when running my tests and the regression service no longer works.
My relevent wdio.conf.js settings are configured as such:
//...
capabilities: {
browserA: {
desiredCapabilities: {
browserName: 'chrome'
}
},
browserB: {
desiredCapabilities: {
browserName: 'chrome'
}
}
},
// ...
services: ['visual-regression'],
visualRegression: {
compare: new VisualRegressionCompare.LocalCompare({
referenceName: getScreenshotName(path.join(process.cwd(), 'screenshots/reference')),
screenshotName: getScreenshotName(path.join(process.cwd(), 'screenshots/taken')),
diffName: getScreenshotName(path.join(process.cwd(), 'screenshots/diff')),
}),
viewportChangePause: 500,
widths: [1280, 1600],
orientations: ['landscape', 'portrait'],
},
Any help would be much appreciated!

How to convert GroovySOAP client code into groovy-wslite?

Hi I am having a bit of trouble figuring out how I can access this web service: http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
Using the groovy Wslite library, seems to work fine with the depreciated Groovy Soap library but I am not allowed to use that.
The libraries are described here:
Groovy Soap Use
Groovy-Wslite
I am totally new to groovy and these technologies in general so forgive my ignorance.
Basically I want this code:
import groovy.swing.SwingBuilder
import groovy.net.soap.SoapClient
proxy = new SoapClient("http://www.webservicex.net/CurrencyConvertor.asmx?WSDL")
def currency = ['USD', 'EUR', 'CAD', 'GBP', 'AUD']
def rate = 0.0
swing = new SwingBuilder()
refresh = swing.action(
name:'Refresh',
closure:this.&refreshText,
mnemonic:'R'
)
frame = swing.frame(title:'Currency Demo') {
panel {
label 'Currency rate from '
comboBox(id:'from', items:currency)
label ' to '
comboBox(id:'to', items:currency)
label ' is '
textField(id:'currency', columns:10, rate.toString())
button(text:'Go !', action:refresh)
}
}
frame.pack()
frame.show()
def refreshText(event) {
rate = proxy.ConversionRate(swing.from.getSelectedItem(), swing.to.getSelectedItem())
swing.currency.text = rate
}
Converted to work with the groovy-wslite library and I cant get it to work no matter what I do.
Here is the Wslite library again.
wslite library
Any help is greatly appreciated.
I find it helpful to use a tool like soapUI first to figure out what request a service is expecting. From there it's a matter of using the markup builder to build that request. The following should work from the groovyConsole:
#Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='0.8.0')
import wslite.soap.*
def client = new SOAPClient('http://www.webservicex.net/CurrencyConvertor.asmx')
def response = client.send(SOAPAction: 'http://www.webserviceX.NET/ConversionRate') {
body {
ConversionRate( xmlns: 'http://www.webserviceX.NET/') {
FromCurrency('GBP')
ToCurrency('USD')
}
}
}
assert response
assert 200 == response.httpResponse.statusCode
println response.ConversionRateResponse.ConversionRateResult.text()

How to start an Amazon EC2 instance programmatically in .NET

I have been attempting to start an instance of EC2 in C# without luck.
When passing in an instance id to start the instance I get an error that the instance cannot be found despite that I am passing in an instance ID that I have obtained from the object property.
I would be most grateful for any tips or pointers with this.
Amazon made huge efforts to integrate its AWS Cloud .Net SDK To VS2008 & VS 2010
1 - Download and Install the AWS SDK msi
2 - Create an AWS Console project, enter your credentials (available from your AWS Console under your login name menu on the top right corner)
3 - Add the following code (see below images).
4 - Your're done. It's very straightforward. You can check the programmatic start/stop success by refreshing your AWS Console Screen.
AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client();
//Start Your Instance
ec2.StartInstances(new StartInstancesRequest().WithInstanceId("i-00000000"));
//Stop it
ec2.StopInstances(new StopInstancesRequest().WithInstanceId("i-00000000"));
You just need to replace "i-00000000" by your instance Id (available in your AWS Management Console)
Hope this helps those googling this and stumbling upon this question (as I did myself) start off quickly. Following these simple steps via these wizards will spare you considerable headaches.
Try something like this with the AWSSDK to start new instances of an "image id":
RunInstancesResponse response = Client.RunInstances(new RunInstancesRequest()
.WithImageId(ami_id)
.WithInstanceType(instance_type)
.WithKeyName(YOUR_KEYPAIR_NAME)
.WithMinCount(1)
.WithMaxCount(max_number_of_instances)
.WithUserData(Convert.ToBase64String(Encoding.UTF8.GetBytes(bootScript.Replace("\r", ""))))
);
(Note: The .WithUserData() is optional and is used above to pass a short shell script.)
If the call is successful the response should contain a list of instances. You can use something like this to create a list of "instance ids":
if (response.IsSetRunInstancesResult() && response.RunInstancesResult.IsSetReservation() && response.RunInstancesResult.Reservation.IsSetRunningInstance())
{
List<string> instance_ids = new List<string>();
foreach (RunningInstance ri in response.RunInstancesResult.Reservation.RunningInstance)
{
instance_ids.Add(ri.InstanceId);
}
// do something with instance_ids
...
}
Be mindful that Amazon AWS instances exist only in one region.. If your instance id i-12345 is in the EU-West-1 region, and you just make a new EC2Client and tell the client to start i-12345 it may well complain that it cannot find that instance, because the client started up in the us-east-1 region, which does not have i-12345 instance
Your call that creates the cient should specify the region, if it is not the default region (I've no idea which AWS region is default, so i specify every time):
AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client(
new Amazon.EC2.AmazonEC2Config().WithServiceURL("https://eu-west-1.ec2.amazonaws.com")
);
try this.
var startRequest = new StartInstancesRequest
{
InstanceIds = new List<string>() { instanceId }
};
bool isError = true;
StartInstancesResponse startInstancesResponse = null;
while (isError)
{
try
{
startInstancesResponse=amazonEc2client.StartInstances(startRequest);
isError = false;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
isError = true;
}
}
Ok, this is the FULL, end-to-end instructions.
1. Install AWSSDK.Core and AWSSDK.EC2 using Nuget Package Manager.
2. Then copy this whole class to your project. AccessKey and Secret are obtained in AWS IAM. You will need to ensure the user you create has "AmazonEC2FullAccess" (You can probably use a lower-level permission policy, I am just lazy here :D). region is your AW S EC2 instance region. and Instance ID can be found in the EC2 dashboard list. Simple, works perfectly... You can also write extra code to manage the response object.
3. Be mindful if you are behind a proxy, you will have to configure it (I havent included code here).
public class AWSClass : IDisposable
{
Amazon.EC2.AmazonEC2Client _client;
public AWSClass(string region, string AccessKey, string Secret)
{
RegionEndpoint EndPoint = RegionEndpoint.GetBySystemName(region);
Amazon.Runtime.BasicAWSCredentials Credentials = new Amazon.Runtime.BasicAWSCredentials(AccessKey, Secret);
_client = new AmazonEC2Client(Credentials, EndPoint);
}
public void Dispose()
{
_client = null;
}
public void StopInstance(string InstanceID)
{
StopInstancesResponse response = _client.StopInstances(new StopInstancesRequest
{
InstanceIds = new List<string> {InstanceID }
});
//Can also do something with the response object too
}
public void StartInstance(string InstanceID)
{
StartInstancesResponse response = _client.StartInstances(new StartInstancesRequest
{
InstanceIds = new List<string> { InstanceID }
});
}
}

How To Use Groovy HTTPBuilder To Get Stories from AgileZen?

I would like to pull stories from Agile Zen using their REST API.
I read:
http://help.agilezen.com/kb/api/overview
http://help.agilezen.com/kb/api/security
Also, I got this to work: http://groovy.codehaus.org/HTTP+Builder
How would one combine the above in order to get Groovy client code to access AgileZen stories?
Here is the code sample which makes one story with id of 1 show up for a specific project whose id is 16854:
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.JSON
public class StoryGetter {
public static void main(String[] args) {
new StoryGetter().getStories()
}
void getStories() {
// http://agilezen.com/project/16854/story/4
// /api/v1/project/16854/story/2
def http = new HTTPBuilder( 'http://agilezen.com' )
http.request( GET, JSON ) {
uri.path = '/api/v1/project/16854/story/1'
headers.'X-Zen-ApiKey' = 'PUT YOUR OWN API KEY HERE'
response.success = { resp, json ->
println "json size is " + json.size()
println json.toString()
}
}
}
}
I had to put in a fake API key in this post since I should not share my API key.
(By the way, this is not using SSL. A follow up question in regards to doing this for a SSL enabled project may come soon.)

Resources