Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphFieldPath"/> class.
        /// </summary>
        /// <param name="fullPath">The full path.</param>
        public GraphFieldPath(string fullPath)
        {
            this.Raw = fullPath;

            // set an initial unknown state of this object
            this.IsValid        = false;
            this.Path           = string.Empty;
            this.Name           = string.Empty;
            this.RootCollection = GraphCollection.Unknown;

            var workingPath = GraphFieldPath.NormalizeFragment(this.Raw);

            // split the path into its fragments
            List <string> pathFragments = workingPath.Split(new[] { RouteConstants.PATH_SEPERATOR }, StringSplitOptions.None).ToList();

            switch (pathFragments[0])
            {
            case RouteConstants.QUERY_ROOT:
                this.RootCollection = GraphCollection.Query;
                break;

            case RouteConstants.MUTATION_ROOT:
                this.RootCollection = GraphCollection.Mutation;
                break;

            case RouteConstants.TYPE_ROOT:
                this.RootCollection = GraphCollection.Types;
                break;

            case RouteConstants.ENUM_ROOT:
                this.RootCollection = GraphCollection.Enums;
                break;

            case RouteConstants.DIRECTIVE_ROOT:
                this.RootCollection = GraphCollection.Directives;
                break;
            }

            // ensure each fragment matches the naming specification
            foreach (var fragment in pathFragments.Skip(this.RootCollection == GraphCollection.Unknown ? 0 : 1))
            {
                if (!this.ValidateFragment(fragment))
                {
                    return;
                }
            }

            this.Name = pathFragments[pathFragments.Count - 1];
            if (pathFragments.Count > 1)
            {
                this.Parent = new GraphFieldPath(string.Join(RouteConstants.PATH_SEPERATOR, pathFragments.Take(pathFragments.Count - 1)));
            }

            this.IsTopLevelField = pathFragments.Count == 1 || (pathFragments.Count == 2 && this.RootCollection > GraphCollection.Unknown); // e.g. "[query]/name"
            this.IsValid         = this.Name.Length > 0;
            this.Path            = this.GeneratePathString(pathFragments);
        }
Пример #2
0
        /// <summary>
        /// Joins a parent and child route segments under the top level field type provided.
        /// </summary>
        /// <param name="routeSegments">The route segments to join.</param>
        /// <returns>System.String.</returns>
        public static string Join(params string[] routeSegments)
        {
            var fragment = string.Join(RouteConstants.PATH_SEPERATOR, routeSegments);

            return(GraphFieldPath.NormalizeFragment(fragment));
        }