-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Initial GraphQL setup #3483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial GraphQL setup #3483
Changes from 1 commit
6d3f5b9
72cd15a
feb6c9d
319c999
a4427bb
bd595d5
e4811d8
22747e6
18f8e7f
a1cb877
343b2c3
2bfea22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Copyright 2019 Dgraph Labs, Inc. and Contributors | ||
| * | ||
| * 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 graphql | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/dgraph-io/dgraph/x" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type options struct { | ||
| schemaFile string | ||
| alpha string | ||
| useCompression bool | ||
| } | ||
|
|
||
| var opt options | ||
|
|
||
| var GraphQL x.SubCommand | ||
|
|
||
| func init() { | ||
| GraphQL.Cmd = &cobra.Command{ | ||
| Use: "graphql", | ||
| Short: "Run the Dgraph GraphQL tool", | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| defer x.StartProfile(GraphQL.Conf).Stop() | ||
| run() | ||
| }, | ||
| } | ||
|
|
||
| GraphQL.EnvPrefix = "DGRAPH_GRAPHQL" | ||
|
|
||
| flags := GraphQL.Cmd.Flags() | ||
| flags.StringP("alpha", "a", "127.0.0.1:9080", | ||
| "Comma-separated list of Dgraph alpha gRPC server addresses") | ||
| flags.BoolP("use_compression", "C", false, | ||
| "Enable compression on connection to alpha server") | ||
| flags.StringP("schema", "s", "schema.graphql", | ||
| "Location of GraphQL schema file") | ||
|
|
||
| cmdInit := &cobra.Command{ | ||
| Use: "init", | ||
| Short: "Initializes Dgraph for a GraphQL schema", | ||
| Args: cobra.NoArgs, | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| defer x.StartProfile(GraphQL.Conf).Stop() | ||
| if err := initDgraph(); err != nil { | ||
| os.Exit(1) | ||
| } | ||
| }, | ||
| } | ||
| cmdInit.Flags().AddFlag(GraphQL.Cmd.Flag("alpha")) | ||
| cmdInit.Flags().AddFlag(GraphQL.Cmd.Flag("schema")) | ||
| GraphQL.Cmd.AddCommand(cmdInit) | ||
|
|
||
| // TLS configuration | ||
| x.RegisterClientTLSFlags(flags) | ||
| } | ||
|
|
||
| func run() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, very long function with too many nested blocks. Should break it down into multiple functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as above - will get spilt up as more parts implemented |
||
| x.PrintVersion() | ||
| opt = options{ | ||
| schemaFile: GraphQL.Conf.GetString("schema"), | ||
| alpha: GraphQL.Conf.GetString("alpha"), | ||
| useCompression: GraphQL.Conf.GetBool("use_compression"), | ||
| } | ||
|
|
||
| fmt.Printf("Bringing up GraphQL API\n") | ||
| fmt.Printf("...Go make a cup of tea while I implement this\n") | ||
| } | ||
|
|
||
| func initDgraph() error { | ||
| x.PrintVersion() | ||
| opt = options{ | ||
| schemaFile: GraphQL.Conf.GetString("schema"), | ||
| alpha: GraphQL.Conf.GetString("alpha"), | ||
| } | ||
|
|
||
| fmt.Printf("\nProcessing schema file %q\n", opt.schemaFile) | ||
| fmt.Printf("Loading into Dgraph at %q\n", opt.alpha) | ||
|
|
||
| fmt.Printf("...Go make a cup of tea while I implement this\n") | ||
|
|
||
| return nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why capital C specifically?