Skip to content

Commit

Permalink
Add support for apollo.config.json,yaml,yml (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas authored Sep 13, 2024
1 parent 5144836 commit d6c6af8
Show file tree
Hide file tree
Showing 18 changed files with 471 additions and 102 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-rats-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-apollo": patch
---

Fixed an issue where the configuration was not reloaded when the `.env.local` file changed.
5 changes: 5 additions & 0 deletions .changeset/wise-files-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-apollo": patch
---

Add support for `apollo.config.yml`, `apollo.config.yaml` and `apollo.config.json`.
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"eslint-config-prettier": "9.0.0",
"eslint-plugin-prettier": "5.0.1",
"graphql-http": "^1.22.1",
"import-fresh": "^3.3.0",
"jest": "29.7.0",
"jest-environment-node": "29.7.0",
"memfs": "4.11.1",
Expand All @@ -93,7 +94,8 @@
"ts-jest": "29.1.2",
"ts-node": "^10.9.2",
"typescript": "^5.5.3",
"vscode-tmgrammar-test": "^0.1.3"
"vscode-tmgrammar-test": "^0.1.3",
"zod-to-json-schema": "^3.23.3"
},
"publisher": "apollographql",
"categories": [
Expand All @@ -103,7 +105,8 @@
"icon": "images/icon-apollo-blue-400x400.png",
"activationEvents": [
"workspaceContains:**/apollo.config.[jt]s",
"workspaceContains:**/apollo.config.[cm]js"
"workspaceContains:**/apollo.config.[cm]js",
"workspaceContains:**/apollo.config.{yaml,yml,json}"
],
"contributes": {
"configuration": {
Expand Down Expand Up @@ -231,6 +234,23 @@
}
}
],
"jsonValidation": [
{
"fileMatch": "apollo.config.json",
"url": "./schemas/apollo.config.schema.json"
}
],
"__yamlValidation": "For context, see https://github.com/redhat-developer/vscode-yaml?tab=readme-ov-file#mapping-a-schema-in-an-extension",
"yamlValidation": [
{
"fileMatch": "apollo.config.yml",
"url": "./schemas/apollo.config.schema.json"
},
{
"fileMatch": "apollo.config.yaml",
"url": "./schemas/apollo.config.schema.json"
}
],
"commands": [
{
"command": "apollographql/selectSchemaTag",
Expand Down
8 changes: 0 additions & 8 deletions sampleWorkspace/localSchema/apollo.config.js

This file was deleted.

4 changes: 4 additions & 0 deletions sampleWorkspace/localSchema/apollo.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
client:
service:
name: localSchema
localSchemaFile: "./starwarsSchema.graphql"
12 changes: 0 additions & 12 deletions sampleWorkspace/localSchemaArray/apollo.config.js

This file was deleted.

8 changes: 8 additions & 0 deletions sampleWorkspace/localSchemaArray/apollo.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"client": {
"service": {
"name": "localMultiSchema",
"localSchemaFile": ["./starwarsSchema.graphql", "./planets.graphql"]
}
}
}
Empty file.
184 changes: 184 additions & 0 deletions schemas/apollo.config.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
{
"allOf": [
{
"$ref": "#/definitions/baseConfig"
},
{
"type": "object",
"properties": {
"client": {
"$ref": "#/definitions/clientConfig"
}
},
"required": [
"client"
]
}
],
"definitions": {
"clientConfig": {
"type": "object",
"properties": {
"service": {
"anyOf": [
{
"type": "string",
"description": "The name of the Apollo Studio graph to use. Alternatively pass in an object to configure a local schema."
},
{
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name your project will be referred to by the Apollo GraphQL extension."
},
"url": {
"type": "string",
"description": "URL of a GraphQL to use for the GraphQL Schema for this project. Needs introspection enabled."
},
"headers": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"default": {},
"description": "Additional headers to send to the server."
},
"skipSSLValidation": {
"type": "boolean",
"default": false,
"description": "Skip SSL validation. May be required for self-signed certificates."
}
},
"required": [
"url"
],
"additionalProperties": false,
"description": "Configuration for using a local schema from a URL."
},
{
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name your project will be referred to by the Apollo GraphQL extension."
},
"localSchemaFile": {
"anyOf": [
{
"type": "string",
"description": "Path to a local schema file to use as GraphQL Schema for this project. Can be a string or an array of strings to merge multiple partial schemas into one."
},
{
"type": "array",
"items": {
"type": "string"
},
"description": "Path to a local schema file to use as GraphQL Schema for this project. Can be a string or an array of strings to merge multiple partial schemas into one."
}
],
"description": "Path to a local schema file to use as GraphQL Schema for this project. Can be a string or an array of strings to merge multiple partial schemas into one."
}
},
"required": [
"localSchemaFile"
],
"additionalProperties": false,
"description": "Configuration for using a local schema from a file."
}
],
"description": "A string to refer to a graph in Apollo Studio, or an object for a local schema."
},
"validationRules": {
"anyOf": [
{
"type": "array",
"description": "Additional validation rules to check for. To use this feature, please use a configuration file format that allows passing JavaScript objects."
}
],
"description": "Additional validation rules to check for. To use this feature, please use a configuration file format that allows passing JavaScript objects."
},
"includes": {
"type": "array",
"items": {
"type": "string"
},
"description": "An array of glob patterns this project should be active on. The Apollo GraphQL extension will only support IntelliSense-like features in files listed here."
},
"excludes": {
"type": "array",
"items": {
"type": "string"
},
"default": [
"**/node_modules",
"**/__tests__"
],
"description": "Files to exclude from this project. The Apollo GraphQL extension will not provide IntelliSense-like features in these files."
},
"tagName": {
"type": "string",
"default": "gql",
"description": "The name of the template literal tag or function used in JavaScript files to declare GraphQL Documents."
},
"clientOnlyDirectives": {
"description": "This option is no longer supported, please remove it from your configuration file."
},
"clientSchemaDirectives": {
"description": "This option is no longer supported, please remove it from your configuration file."
},
"statsWindow": {
"description": "This option is no longer supported, please remove it from your configuration file."
},
"name": {
"description": "This option is no longer supported, please remove it from your configuration file."
},
"referenceId": {
"description": "This option is no longer supported, please remove it from your configuration file."
},
"version": {
"description": "This option is no longer supported, please remove it from your configuration file."
}
},
"required": [
"service"
],
"additionalProperties": false,
"description": "Configuration for a Client project."
},
"engineConfig": {
"type": "object",
"properties": {
"endpoint": {
"type": "string",
"default": "https://graphql.api.apollographql.com/api/graphql",
"description": "The URL of the Apollo Studio API."
},
"apiKey": {
"type": "string",
"description": "The API key to use for Apollo Studio. If possible, use a `.env` file or `.env.local` file instead to store secrets like this."
}
},
"additionalProperties": false,
"description": "Network configuration for Apollo Studio API."
},
"baseConfig": {
"type": "object",
"properties": {
"engine": {
"$ref": "#/definitions/engineConfig",
"default": {},
"description": "Network configuration for Apollo Studio API."
},
"client": {
"description": "Configuration for a Client project."
},
"service": {
"description": "This option is no longer supported, please remove it from your configuration file."
}
},
"additionalProperties": false
}
},
"$schema": "http://json-schema.org/draft-07/schema#"
}
40 changes: 39 additions & 1 deletion src/build.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
const esbuild = require("esbuild");
const { zodToJsonSchema } = require("zod-to-json-schema");
const { writeFileSync } = require("fs");
const importFresh = require("import-fresh");

const production = process.argv.includes("--production");
const watch = process.argv.includes("--watch");

async function main() {
const ctx = await esbuild.context({
entryPoints: ["src/extension.ts", "src/language-server/server.ts"],
entryPoints: [
"src/extension.ts",
"src/language-server/server.ts",
"src/language-server/config/config.ts",
],
bundle: true,
format: "cjs",
minify: production,
Expand All @@ -19,6 +26,7 @@ async function main() {
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
buildJsonSchemaPlugin,
],
});
if (watch) {
Expand Down Expand Up @@ -51,6 +59,36 @@ const esbuildProblemMatcherPlugin = {
},
};

const buildJsonSchemaPlugin = {
name: "build-json-schema",
setup(build) {
build.onEnd(() => {
const {
configSchema,
clientConfig,
// roverConfig,
engineConfig,
baseConfig,
// @ts-ignore
} = importFresh("../lib/language-server/config/config.js");

const jsonSchema = zodToJsonSchema(configSchema, {
errorMessages: true,
definitions: {
clientConfig,
//roverConfig,
engineConfig,
baseConfig,
},
});
writeFileSync(
"./schemas/apollo.config.schema.json",
JSON.stringify(jsonSchema, null, 2),
);
});
},
};

main().catch((e) => {
console.error(e);
process.exit(1);
Expand Down
Loading

0 comments on commit d6c6af8

Please sign in to comment.