diff --git a/src/Dev/Initialise.php b/src/Dev/Initialise.php index a4240e80..f66733c5 100644 --- a/src/Dev/Initialise.php +++ b/src/Dev/Initialise.php @@ -1,6 +1,5 @@ getVar('help')) { + $this->showHelp(); + return; + } + $appNamespace = $request->getVar('namespace'); - Schema::invariant( - $appNamespace, - 'Please provide a base namespace for your app, e.g. "namespace=App" or "namespace=MyVendor\MyProject"' - ); + + if (!$appNamespace) { + echo "Please provide a base namespace for your app, e.g. \"namespace=App\" or \"namespace=MyVendor\MyProject\".\nFor help, run \"dev/graphql/init help=1\"\n"; + return; + } + $this->appNamespace = $appNamespace; $this->projectDir = ModuleManifest::config()->get('project'); - $schemaName = $request->getVar('name'); if ($schemaName) { $this->schemaName = $schemaName; @@ -140,13 +139,14 @@ private function createGraphQLConfig(): void echo "Graphql config directory already exists. Skipping." . PHP_EOL; return; } - echo "Creating graphql config directory: $this->graphqlConfigDir" . PHP_EOL; - mkdir($absGraphQLDir, $this->perms); + + echo "Creating graphql config directory: $this->graphqlConfigDir" . PHP_EOL; + mkdir($absGraphQLDir, $this->perms); foreach (['models', 'config', 'types', 'queries', 'mutations'] as $file) { touch(Path::join($absGraphQLDir, "$file.yml")); } - $configPath = Path::join($absGraphQLDir, 'config.yml'); - $defaultConfig = <<appNamespace\Resolvers YAML; @@ -172,6 +172,7 @@ private function createProjectConfig(): void $this->schemaName: src: - $this->projectDir/$this->graphqlConfigDir + YAML; file_put_contents($absConfigFile, $defaultProjectConfig); } @@ -206,16 +207,44 @@ private function createResolvers(): void */ class Resolvers { - - public static function resolveMyQuery(\$obj, array \$args, \$context): array + public static function resolveMyQuery(\$obj, array \$args, array \$context): array { // Return the result of query { myQuery { ... } } return []; } - } PHP; file_put_contents($resolverFile, $resolverCode); } + + /** + * Outputs help text to the console + */ + private function showHelp(): void + { + echo <<: The name of the schema. Default: "default" + +: The folder where the flushless graphql config files will go. Default: "_graphql" + +: The subfolder of src/ where your GraphQL code (the resolver class) will go. Follows PSR-4 based on the namespace argument (default: "GraphQL") + +TXT; + } }