Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.eclipse.microprofile.graphql.client.core;


import java.util.List;

import static java.util.Arrays.asList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface Document extends Buildable {
/*
Static factory methods
*/
static Document document(Operation... operations) {
static Document document(FragmentOrOperation... operations) {
Document document = getNewInstanceOf(Document.class);

document.setOperations(asList(operations));
Expand All @@ -38,5 +38,5 @@ static Document document(Operation... operations) {
*/
List<Operation> getOperations();

void setOperations(List<Operation> operations);
void setOperations(List<FragmentOrOperation> operations);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ static Enum gqlEnum(String value) {
return gqlEnum;
}


/*
Getter/Setter
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static java.util.Collections.emptyList;
import static org.eclipse.microprofile.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;

public interface Field extends Buildable {
public interface Field extends FieldOrFragment {
/*
Static factory methods
*/
Expand All @@ -41,7 +41,7 @@ static Field field(String name) {
}

// (name, subfields)
static Field field(String name, Field... fields) {
static Field field(String name, FieldOrFragment... fields) {
Field field = getNewInstanceOf(Field.class);

field.setName(name);
Expand Down Expand Up @@ -84,7 +84,7 @@ static Field field(String name, List<Argument> args, Field... fields) {

void setArguments(List<Argument> arguments);

List<Field> getFields();
List<FieldOrFragment> getFields();

void setFields(List<Field> fields);
void setFields(List<FieldOrFragment> fields);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eclipse.microprofile.graphql.client.core;

/**
* Represents one of these nodes in a GraphQL document:
* - regular field (name), for example "color"
* - reference to a named fragment, for example "...comparisonFields"
* - an inline fragment, for example ("... on Person { name } ")
*/
public interface FieldOrFragment extends Buildable {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eclipse.microprofile.graphql.client.core;

import java.util.List;

import static org.eclipse.microprofile.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static java.util.Arrays.asList;

/**
* Represents a named fragment definition in a GraphQL document. Such definition consists of a name,
* target type, and a set of fields.
*/
public interface Fragment extends FragmentOrOperation {
/*
* Static factory methods
*/
static List<Fragment> fragments(Fragment... fragments) {
return asList(fragments);
}

static FragmentBuilder fragment(String name) {
return new FragmentBuilder(name);
}

/*
* Getter/Setter
*/
String getName();

void setName(String name);

String getTargetType();

void setTargetType(String name);

List<FieldOrFragment> getFields();

void setFields(List<FieldOrFragment> fields);

class FragmentBuilder {

private String name;

private String targetType;

private List<FieldOrFragment> fields;

FragmentBuilder(String name) {
this.name = name;
}

public Fragment on(String targetType, FieldOrFragment... fields) {
this.targetType = targetType;
this.fields = asList(fields);
return build();
}

Fragment build() {
Fragment fragment = getNewInstanceOf(Fragment.class);
fragment.setName(name);
fragment.setTargetType(targetType);
fragment.setFields(fields);
return fragment;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.eclipse.microprofile.graphql.client.core;

/**
* Represents a node in a GraphQL document that can contain either an operation (query/mutation/subscription),
* or a definition of a named fragment. On the top level, a GraphQL document basically consists of a list
* of these nodes.
*/
public interface FragmentOrOperation extends Buildable {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.eclipse.microprofile.graphql.client.core;


import static org.eclipse.microprofile.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;

/**
* Represents a reference to a named fragment.
*/
public interface FragmentReference extends FieldOrFragment {

/**
* Create a fragment reference by specifying the name of the target fragment.
* In the resulting document, this will appear as `...FRAGMENTNAME`
*/
static FragmentReference fragmentRef(String name) {
FragmentReference ref = getNewInstanceOf(FragmentReference.class);
ref.setName(name);
return ref;
}

/**
* Create a fragment reference by providing a built instance of a named fragment.
* This will actually only use the name of the fragment - in the resulting document,
* this will appear as `...FRAGMENTNAME`
*/
static FragmentReference fragmentRef(Fragment fragment) {
FragmentReference ref = getNewInstanceOf(FragmentReference.class);
ref.setName(fragment.getName());
return ref;
}

String getName();

void setName(String name);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.eclipse.microprofile.graphql.client.core;

import java.util.List;

import static org.eclipse.microprofile.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static java.util.Arrays.asList;

/**
* Represents an inline fragment in a GraphQL document. This can be used
* anywhere where a field is expected (thus it implements `FieldOrFragment`).
*/
public interface InlineFragment extends FieldOrFragment {

static InlineFragment on(String type, FieldOrFragment... fields) {
InlineFragment fragment = getNewInstanceOf(InlineFragment.class);

fragment.setType(type);
fragment.setFields(asList(fields));

return fragment;
}

String getType();

void setType(String name);

List<FieldOrFragment> getFields();

void setFields(List<FieldOrFragment> fields);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import java.util.List;

import static java.util.Arrays.asList;
import static org.eclipse.microprofile.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static java.util.Arrays.asList;

public interface InputObject extends Buildable {
/*
Expand Down
Loading