// Path: kramer/src/main/java/com/chiralbehaviors/layout/schema/Primitive.java
// public class Primitive extends SchemaNode {
// 
//     private double defaultWidth = 0;
// 
//     public Primitive() {
//         super();
//     }
// 
//     public Primitive(String field) {
//         super(field);
//     }
// 
//     public double getDefaultWidth() {
//         return defaultWidth;
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("Primitive [%s]", label);
//     }
// 
//     @Override
//     public String toString(int indent) {
//         return toString();
//     }
// }
// 
// Path: kramer/src/main/java/com/chiralbehaviors/layout/schema/Relation.java
// public class Relation extends SchemaNode {
//     private boolean                autoFold = true;
//     private final List<SchemaNode> children = new ArrayList<>();
//     private Relation               fold;
// 
//     public Relation(String label) {
//         super(label);
//     }
// 
//     public void addChild(SchemaNode child) {
//         children.add(child);
//     }
// 
//     public Relation getAutoFoldable() {
//         if (fold != null) {
//             return fold;
//         }
//         return autoFold && children.size() == 1
//                && children.get(children.size() - 1) instanceof Relation
//                                                                         ? (Relation) children.get(0)
//                                                                         : null;
//     }
// 
//     public SchemaNode getChild(String field) {
//         for (SchemaNode child : children) {
//             if (child.getField()
//                      .equals(field)) {
//                 return child;
//             }
//         }
//         return null;
//     }
// 
//     public List<SchemaNode> getChildren() {
//         return children;
//     }
// 
//     public Relation getFold() {
//         return fold;
//     }
// 
//     @JsonProperty
//     public boolean isFold() {
//         return fold != null;
//     }
// 
//     @Override
//     public boolean isRelation() {
//         return true;
//     }
// 
//     public void setFold(boolean fold) {
//         this.fold = (fold && children.size() == 1 && children.get(0)
//                                                              .isRelation()) ? (Relation) children.get(0)
//                                                                             : null;
//     }
// 
//     @Override
//     public String toString() {
//         return toString(0);
//     }
// 
//     @Override
//     public String toString(int indent) {
//         StringBuffer buf = new StringBuffer();
//         buf.append(String.format("Relation [%s]", label));
//         buf.append('\n');
//         children.forEach(c -> {
//             for (int i = 0; i < indent; i++) {
//                 buf.append("    ");
//             }
//             buf.append("  - ");
//             buf.append(c.toString(indent + 1));
//             if (!c.equals(children.get(children.size() - 1))) {
//                 buf.append('\n');
//             }
//         });
//         return buf.toString();
//     }
// }


import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import com.chiralbehaviors.layout.schema.Primitive;
import com.chiralbehaviors.layout.schema.Relation;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import graphql.language.Definition;
import graphql.language.Field;
import graphql.language.FragmentSpread;
import graphql.language.InlineFragment;
import graphql.language.OperationDefinition;
import graphql.language.OperationDefinition.Operation;
import graphql.language.Selection;
import graphql.parser.Parser;
/**
 * Copyright (c) 2016 Chiral Behaviors, LLC, all rights reserved.
 * 
 * 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 com.chiralbehaviors.layout.graphql;





/**
 * 
 * @author halhildebrand
 *
 */
public interface GraphQlUtil {
    static class QueryException extends Exception {
        private static final long serialVersionUID = 1L;
        private final ArrayNode   errors;

        public QueryException(ArrayNode errors) {
            super(errors.toString());
            this.errors = errors;
        }

        public ArrayNode getErrors() {
            return errors;
        }
    }

    static class QueryRequest {
        public String              operationName;
        public String              query;
        public Map<String, Object> variables = Collections.emptyMap();

        public QueryRequest() {
        }

        public QueryRequest(String query, Map<String, Object> variables) {
            this.query = query;
            this.variables = variables;
        }

        @Override
        public String toString() {
            return "QueryRequest [query=" + query + ", variables=" + variables
                   + "]";
        }
    }

// Path: kramer/src/main/java/com/chiralbehaviors/layout/schema/Primitive.java
// public class Primitive extends SchemaNode {
// 
//     private double defaultWidth = 0;
// 
//     public Primitive() {
//         super();
//     }
// 
//     public Primitive(String field) {
//         super(field);
//     }
// 
//     public double getDefaultWidth() {
//         return defaultWidth;
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("Primitive [%s]", label);
//     }
// 
//     @Override
//     public String toString(int indent) {
//         return toString();
//     }
// }
// 
// Path: kramer/src/main/java/com/chiralbehaviors/layout/schema/Relation.java
// public class Relation extends SchemaNode {
//     private boolean                autoFold = true;
//     private final List<SchemaNode> children = new ArrayList<>();
//     private Relation               fold;
// 
//     public Relation(String label) {
//         super(label);
//     }
// 
//     public void addChild(SchemaNode child) {
//         children.add(child);
//     }
// 
//     public Relation getAutoFoldable() {
//         if (fold != null) {
//             return fold;
//         }
//         return autoFold && children.size() == 1
//                && children.get(children.size() - 1) instanceof Relation
//                                                                         ? (Relation) children.get(0)
//                                                                         : null;
//     }
// 
//     public SchemaNode getChild(String field) {
//         for (SchemaNode child : children) {
//             if (child.getField()
//                      .equals(field)) {
//                 return child;
//             }
//         }
//         return null;
//     }
// 
//     public List<SchemaNode> getChildren() {
//         return children;
//     }
// 
//     public Relation getFold() {
//         return fold;
//     }
// 
//     @JsonProperty
//     public boolean isFold() {
//         return fold != null;
//     }
// 
//     @Override
//     public boolean isRelation() {
//         return true;
//     }
// 
//     public void setFold(boolean fold) {
//         this.fold = (fold && children.size() == 1 && children.get(0)
//                                                              .isRelation()) ? (Relation) children.get(0)
//                                                                             : null;
//     }
// 
//     @Override
//     public String toString() {
//         return toString(0);
//     }
// 
//     @Override
//     public String toString(int indent) {
//         StringBuffer buf = new StringBuffer();
//         buf.append(String.format("Relation [%s]", label));
//         buf.append('\n');
//         children.forEach(c -> {
//             for (int i = 0; i < indent; i++) {
//                 buf.append("    ");
//             }
//             buf.append("  - ");
//             buf.append(c.toString(indent + 1));
//             if (!c.equals(children.get(children.size() - 1))) {
//                 buf.append('\n');
//             }
//         });
//         return buf.toString();
//     }
// }


// Path: kramer-ql/src/main/java/com/chiralbehaviors/layout/graphql/GraphQlUtil.java
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import com.chiralbehaviors.layout.schema.Primitive;
import com.chiralbehaviors.layout.schema.Relation;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import graphql.language.Definition;
import graphql.language.Field;
import graphql.language.FragmentSpread;
import graphql.language.InlineFragment;
import graphql.language.OperationDefinition;
import graphql.language.OperationDefinition.Operation;
import graphql.language.Selection;
import graphql.parser.Parser;

/**
 * Copyright (c) 2016 Chiral Behaviors, LLC, all rights reserved.
 * 
 * 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 com.chiralbehaviors.layout.graphql;





/**
 * 
 * @author halhildebrand
 *
 */
public interface GraphQlUtil {
    static class QueryException extends Exception {
        private static final long serialVersionUID = 1L;
        private final ArrayNode   errors;

        public QueryException(ArrayNode errors) {
            super(errors.toString());
            this.errors = errors;
        }

        public ArrayNode getErrors() {
            return errors;
        }
    }

    static class QueryRequest {
        public String              operationName;
        public String              query;
        public Map<String, Object> variables = Collections.emptyMap();

        public QueryRequest() {
        }

        public QueryRequest(String query, Map<String, Object> variables) {
            this.query = query;
            this.variables = variables;
        }

        @Override
        public String toString() {
            return "QueryRequest [query=" + query + ", variables=" + variables
                   + "]";
        }
    }

    static Relation buildSchema(Field parentField) {