Skip to content

Commit

Permalink
cleanup and fixed variable request
Browse files Browse the repository at this point in the history
  • Loading branch information
FarshidRoohi committed Jul 29, 2019
1 parent 679fdb9 commit 761fc08
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 365 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String getFields() {

//TODO this needs a Illegal Exception.

List<Field> fields = Arrays.asList(getModel().getClass().getDeclaredFields());
Field[] fields = getModel().getClass().getDeclaredFields();
List<String> result = new ArrayList<>();
for (Field field : fields) {
if (field.getAnnotation(UnInject.class) != null) {
Expand Down
3 changes: 0 additions & 3 deletions qlroid/src/main/java/com/github/imanx/QLroid/Mutation.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.github.imanx.QLroid;


import android.util.Log;

import com.github.imanx.QLroid.request.Argument;

import org.json.JSONObject;
Expand Down Expand Up @@ -58,7 +56,6 @@ public String getQuery() {
params,
fields
);
Log.i("AAAA", "getQuery: " + query);
return query;
}
}
34 changes: 20 additions & 14 deletions qlroid/src/main/java/com/github/imanx/QLroid/Query.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.imanx.QLroid;

import org.json.JSONObject;

/**
* Created by ImanX.
* QLroid | Copyrights 2018 ZarinPal Crop.
Expand All @@ -19,29 +21,33 @@ public Query() {
@Override
public String getQuery() {

String query = "query { %s %s { %s }}";
String operationName = getOperationName();
String responseName = "";
String query = "query qr %s { %s %s(%s)%s}";

if (getModel() != null) {
responseName = String.format("%s :", getModel().getResponseModelName());
}
JSONObject var = null;
String mutationRaw = "";
String params = "";

String fields = getFields().isEmpty() ? "" : "{" + getFields() + "}";

if (getModel() != null) {
return "query { " + getModel().buildQuery(getArgument(), responseName + "" + getOperationName()) + "}";
fields = getModel().buildQuery(null, "");
}


if (getArgument() != null) {
operationName = String.format("(%s)", getArgument().getQueryRaw());
mutationRaw = getArgument().getMutationRaw();
params = getArgument().getParameter();
var = getArgument().getQueryRaw();
}

return String.format(
query,
responseName,
operationName,
getFields()
setVariables(var);

query = String.format(query,
"(" + mutationRaw + ")",
getModel() == null ? "" : String.format("%s :", getModel().getResponseModelName()),
getOperationName(),
params,
fields
);
return query;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ class Request private constructor(private val builder: Builder) {
this.graphCore = mutation
this.context = context
}

constructor(context: Context, uri: Uri) {
this.uri = uri
this.context = context
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,61 +1,16 @@
package graphsample.imanx.github.com.comgithubimanxgraphsample;

import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.github.imanx.QLroid.Query;
import com.github.imanx.QLroid.callback.Callback;
import com.github.imanx.QLroid.request.Header;
import com.github.imanx.QLroid.request.Request;

public class MainActivity extends AppCompatActivity {

public static final String TAG = MainActivity.class.getSimpleName();

private String baseUrl = "https://plus.zarinpal.com/api/graphql/my";
private String token = "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImE3MWNmZjU1YWI0NGY5YjY0M2Q4NmY1NTYzNWRlZjI5MzMzODVkYzU3OGFkMGJkZTg2Mjk0MjQzMmQxYmU4MzEzZDgxOTYwMjgwNjRiZjRmIn0.eyJhdWQiOiIxIiwianRpIjoiYTcxY2ZmNTVhYjQ0ZjliNjQzZDg2ZjU1NjM1ZGVmMjkzMzM4NWRjNTc4YWQwYmRlODYyOTQyNDMyZDFiZTgzMTNkODE5NjAyODA2NGJmNGYiLCJpYXQiOjE1Mzg5ODU2MDQsIm5iZiI6MTUzODk4NTYwNCwiZXhwIjoxNTcwNTIxNjAxLCJzdWIiOiIyIiwic2NvcGVzIjpbXX0.yvCi-idUpafQvp2DBLcFydKM2zV92xgaD1IPPKZrwcYGj58rnhYx_vR66iKzFaHTgSH9UgnyJ-uC0lxVIgE1AvTu_C1dCQRRoICVB2EXVCi-sBEojs4GOqPoMRszj1eeqZwLT85iUiXEXWaNU7GLskBWtGcotq24IbtjK3v67vkl62pzhBxsnNzZX8bKIc9ahKYDfydl8DHuFoZMW4Js3bacI9fsD3Mv_416tkPaRZK93uViq9ifYsWyHhfpR4m-zcdcbdCGymTOLDKorxAkRuB8qqdHcSSTPG-wB1pq-6vyJ0v8LVUnPnkzwgAmiwGipzMJBlz3HRFkH9g2ASEyuo-swcROpKVU-RvysYh-C0z3ss6c6lC85MR3xH30bzgeWN88YrNLw90OK3lesVgs-Xs1VqZbdUaO2p2Y0eoMjOgHyE9hGkFnxEcfCnGwpvKbe0b2h5CdjZepcfF2-qveVGBDnSkh1e3jztBGjcQmtoN8cBNgxq1TPBpBx_TTFXYffJUMoFj1K4iIAvuhTMw0In8nzIwD3o0uXENKelJzE3uEKyICZ1dg3bQZdz3sGRoPADqPnzOJQ1FbvsL3OQtrH9Qvkfv-U27w5KKUYb7r4-OxY4eiwpeNhIWe49VtptfbNYznfH4hqEdny9Ak5qgIXnLBvhanEPXE24nyYT3HonI";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Header header = new Header();
header.append("Authorization", token);
header.append("Accept", "application/json");

getQuery().setHeader(header)
.setTimeout(10)
.build()
.enqueue(new Callback() {
@Override
public void onResponse(String response) {
Log.i(TAG, "onResponse: " + response);
}

@Override
public void onFailure(int httpCode, String data) {
Log.i(TAG, "onFailure: " + httpCode + " || " + data);
}
});

}

public Request.Builder getQuery() {
return new Request.Builder(this, Uri.parse(baseUrl), new Query(new Me()) {
@Nullable
@Override
public String getOperationName() {
return "Me";
}
// TODO : Add sample use github GraphQL API

// @Override
// public String[] getResponseFields() {
// return new String[]{"first_name", "avatar"};
// }
});
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 761fc08

Please sign in to comment.