-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/1.1' into 'master'
Release/1.1 See merge request yuanwq/shopify4j!36
- Loading branch information
Showing
47 changed files
with
9,058 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ build | |
gen | ||
out | ||
.idea | ||
store.properties | ||
test.properties | ||
|
||
# Ignore Gradle GUI config | ||
gradle-app.setting | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
dependencies { | ||
// lombok | ||
annotationProcessor("org.projectlombok:lombok:$lombokVersion") | ||
compileOnly("org.projectlombok:lombok:$lombokVersion") | ||
testCompileOnly("org.projectlombok:lombok:$lombokVersion") | ||
|
||
api(project(":shopify4j-core")) | ||
api(project(":graphql-partner-schema")) | ||
|
||
api("com.squareup.okhttp3:okhttp:$okhttpVersion") | ||
|
||
api("commons-io:commons-io:$commonsIOVersion") | ||
|
||
// test | ||
testImplementation("junit:junit:$junitVersion") | ||
testImplementation("org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion") | ||
|
||
} | ||
|
||
description "Java SDK for Shopify Partner GraphQL API" | ||
apply from: "$rootDir/publish.gradle" |
67 changes: 67 additions & 0 deletions
67
...-partner-api/src/main/java/codemeans/shopify4j/graphql/partner/DefaultGraphqlPartner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package codemeans.shopify4j.graphql.partner; | ||
|
||
import codemeans.shopify4j.core.exception.GraphqlApiException; | ||
import codemeans.shopify4j.graphql.GraphqlInvoker; | ||
import codemeans.shopify4j.graphql.partner.exception.GraphqlPartnerQueryException; | ||
import codemeans.shopify4j.graphql.partner.exception.GraphqlPartnerSchemaException; | ||
import codemeans.shopify4j.graphql.partner.types.QueryResponse; | ||
import codemeans.shopify4j.graphql.partner.types.QueryRootQuery; | ||
import com.shopify.graphql.support.SchemaViolationError; | ||
|
||
/** | ||
* @author: yuanwq | ||
* @date: 2021-01-26 | ||
*/ | ||
public class DefaultGraphqlPartner implements GraphqlPartner { | ||
|
||
private final String organizationId; | ||
private final String apiVersion; | ||
private final String graphqlEndpoint; | ||
private final GraphqlInvoker invoker; | ||
|
||
public DefaultGraphqlPartner(String organizationId, String apiVersion, | ||
GraphqlInvoker invoker) { | ||
this.organizationId = organizationId; | ||
this.apiVersion = apiVersion; | ||
this.graphqlEndpoint = String.format("https://partners.shopify.com/%s/api/%s/graphql.json", | ||
this.organizationId, apiVersion); | ||
this.invoker = invoker; | ||
} | ||
|
||
@Override | ||
public String getOrganizationId() { | ||
return organizationId; | ||
} | ||
|
||
@Override | ||
public String getApiVersion() { | ||
return apiVersion; | ||
} | ||
|
||
@Override | ||
public String getGraphqlEndpoint() { | ||
return graphqlEndpoint; | ||
} | ||
|
||
@Override | ||
public String request(String query) throws GraphqlApiException { | ||
return invoker.request(graphqlEndpoint, query); | ||
} | ||
|
||
@Override | ||
public QueryResponse query(QueryRootQuery query) throws GraphqlApiException { | ||
String resp = null; | ||
try { | ||
String queryBody = query.toString(); | ||
resp = invoker.request(graphqlEndpoint, queryBody); | ||
QueryResponse response = QueryResponse.fromJson(resp); | ||
if (response.getErrors() != null && !response.getErrors().isEmpty()) { | ||
throw new GraphqlPartnerQueryException(query, response); | ||
} | ||
return response; | ||
} catch (SchemaViolationError schemaViolationError) { | ||
throw new GraphqlPartnerSchemaException(query, resp, schemaViolationError); | ||
} | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
graphql-partner-api/src/main/java/codemeans/shopify4j/graphql/partner/GraphqlPartner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package codemeans.shopify4j.graphql.partner; | ||
|
||
import codemeans.shopify4j.core.exception.GraphqlApiException; | ||
import codemeans.shopify4j.graphql.partner.types.QueryResponse; | ||
import codemeans.shopify4j.graphql.partner.types.QueryRootQuery; | ||
|
||
/** | ||
* @author: yuanwq | ||
* @date: 2021-01-26 | ||
*/ | ||
public interface GraphqlPartner { | ||
|
||
String getOrganizationId(); | ||
|
||
String getApiVersion(); | ||
|
||
String getGraphqlEndpoint(); | ||
|
||
/** | ||
* 原始请求 | ||
*/ | ||
String request(String query) throws GraphqlApiException; | ||
|
||
QueryResponse query(QueryRootQuery query) throws GraphqlApiException; | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...-partner-api/src/main/java/codemeans/shopify4j/graphql/partner/GraphqlPartnerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package codemeans.shopify4j.graphql.partner; | ||
|
||
import codemeans.shopify4j.core.base.CachedClientFactory; | ||
import codemeans.shopify4j.core.base.ClientFactory; | ||
import codemeans.shopify4j.graphql.GraphqlInvoker; | ||
import lombok.Data; | ||
import lombok.NonNull; | ||
|
||
/** | ||
* @author: yuanwq | ||
* @date: 2021-01-12 | ||
*/ | ||
@Data | ||
public class GraphqlPartnerFactory implements ClientFactory<GraphqlPartner> { | ||
|
||
private final GraphqlInvoker graphqlInvoker; | ||
private String apiVersion = "2021-04"; | ||
|
||
public GraphqlPartnerFactory(@NonNull GraphqlInvoker graphqlInvoker) { | ||
this.graphqlInvoker = graphqlInvoker; | ||
} | ||
|
||
@Override | ||
public GraphqlPartner getClient(String organizationId) { | ||
return new DefaultGraphqlPartner(organizationId, apiVersion, graphqlInvoker); | ||
} | ||
|
||
public CachedGraphqlPartnerFactory cached() { | ||
return new CachedGraphqlPartnerFactory(this); | ||
} | ||
|
||
public static class CachedGraphqlPartnerFactory extends CachedClientFactory<GraphqlPartner> { | ||
|
||
protected CachedGraphqlPartnerFactory(ClientFactory delegate) { | ||
super(delegate); | ||
} | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...main/java/codemeans/shopify4j/graphql/partner/exception/GraphqlPartnerQueryException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package codemeans.shopify4j.graphql.partner.exception; | ||
|
||
import codemeans.shopify4j.core.exception.GraphqlApiException; | ||
import codemeans.shopify4j.graphql.partner.types.QueryResponse; | ||
import codemeans.shopify4j.graphql.partner.types.QueryRootQuery; | ||
import com.shopify.graphql.support.Error; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import lombok.Getter; | ||
|
||
/** | ||
* @author: yuanwq | ||
* @date: 2021-01-26 | ||
*/ | ||
public class GraphqlPartnerQueryException extends GraphqlApiException { | ||
|
||
@Getter | ||
private QueryRootQuery query; | ||
@Getter | ||
private QueryResponse response; | ||
@Getter | ||
private List<Error> errors; | ||
|
||
public GraphqlPartnerQueryException(QueryRootQuery query, QueryResponse response) { | ||
super("Query: " + query + ", Response: " + response.toJson()); | ||
this.query = query; | ||
this.response = response; | ||
this.errors = response.getErrors() != null ? response.getErrors() : Collections.emptyList(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...ain/java/codemeans/shopify4j/graphql/partner/exception/GraphqlPartnerSchemaException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package codemeans.shopify4j.graphql.partner.exception; | ||
|
||
import codemeans.shopify4j.core.exception.GraphqlApiException; | ||
import com.shopify.graphql.support.Query; | ||
import com.shopify.graphql.support.SchemaViolationError; | ||
import lombok.Getter; | ||
|
||
/** | ||
* @author: yuanwq | ||
* @date: 2021-01-26 | ||
*/ | ||
public class GraphqlPartnerSchemaException extends GraphqlApiException { | ||
|
||
@Getter | ||
private Query query; | ||
@Getter | ||
private SchemaViolationError schemaViolationError; | ||
|
||
public GraphqlPartnerSchemaException(Query query, String resp, | ||
SchemaViolationError schemaViolationError) { | ||
super("Query: " + query + ", Resp: " + resp, schemaViolationError); | ||
this.query = query; | ||
this.schemaViolationError = schemaViolationError; | ||
} | ||
|
||
} |
Oops, something went wrong.