-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add relay-config library #4780
Open
robertf224
wants to merge
9
commits into
facebook:main
Choose a base branch
from
robertf224:rf/add-relay-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,481
−7
Open
Add relay-config library #4780
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f9907ea
initial impl
robertf224 b935604
remove from babel-plugin for now + add tests
robertf224 eb5872a
add flow annotation
robertf224 79ed311
downgrade json-schema-to-typescript
robertf224 1b60d4e
support uint8 in json schema
robertf224 6835660
remove saveConfig + fix tests
robertf224 ae4871d
update readme
robertf224 5b73b13
Merge branch 'main' into rf/add-relay-config
robertf224 e5de754
downgrade dep
robertf224 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# relay-config | ||
|
||
A utility library for loading and saving Relay compiler config files. |
5 changes: 5 additions & 0 deletions
5
packages/relay-config/__tests__/fixtures/invalid-config/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "my-app", | ||
"version": "1.0.0", | ||
"relay": {} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/relay-config/__tests__/fixtures/js-config/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "my-app", | ||
"version": "1.0.0" | ||
} |
1 change: 1 addition & 0 deletions
1
packages/relay-config/__tests__/fixtures/js-config/relay.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {language: 'typescript', schema: 'schema.graphql'}; |
4 changes: 4 additions & 0 deletions
4
packages/relay-config/__tests__/fixtures/json-config/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "my-app", | ||
"version": "1.0.0" | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/relay-config/__tests__/fixtures/json-config/relay.config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"language": "typescript", | ||
"schema": "schema.graphql" | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/relay-config/__tests__/fixtures/no-config/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "my-app", | ||
"version": "1.0.0" | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/relay-config/__tests__/fixtures/package-json-config/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "my-app", | ||
"version": "1.0.0", | ||
"relay": { | ||
"language": "typescript", | ||
"schema": "schema.graphql" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
* @format | ||
* @oncall relay | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const loadConfig = require('../loadConfig'); | ||
const path = require('path'); | ||
|
||
describe('loadConfig', () => { | ||
it('Returns undefined if there is no config available', () => { | ||
expect( | ||
loadConfig(path.join(__dirname, 'fixtures/no-config')), | ||
).toBeUndefined(); | ||
}); | ||
|
||
it('Fails if the config is invalid', () => { | ||
expect(() => | ||
loadConfig(path.join(__dirname, 'fixtures/invalid-config')), | ||
).toThrow(); | ||
}); | ||
|
||
it('Properly loads relay.config.js files', () => { | ||
expect(loadConfig(path.join(__dirname, 'fixtures/js-config'))).toEqual({ | ||
language: 'typescript', | ||
schema: 'schema.graphql', | ||
}); | ||
}); | ||
|
||
it('Properly loads relay.config.json files', () => { | ||
expect(loadConfig(path.join(__dirname, 'fixtures/json-config'))).toEqual({ | ||
language: 'typescript', | ||
schema: 'schema.graphql', | ||
}); | ||
}); | ||
|
||
it('Properly loads package.json config', () => { | ||
expect( | ||
loadConfig(path.join(__dirname, 'fixtures/package-json-config')), | ||
).toEqual({ | ||
language: 'typescript', | ||
schema: 'schema.graphql', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @oncall relay | ||
*/ | ||
|
||
import { ConfigFile as RelayConfig } from './RelayConfig'; | ||
|
||
declare function loadConfig(): Promise<RelayConfig>; | ||
|
||
declare function saveConfig( | ||
config: RelayConfig, | ||
folder: string, | ||
configType: 'relay.config.js' | 'relay.config.json' | 'package.json', | ||
): Promise<void>; | ||
|
||
export { loadConfig, saveConfig, RelayConfig }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
* @format | ||
* @oncall relay | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const loadConfig = require('./loadConfig'); | ||
|
||
module.exports = {loadConfig}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
* @format | ||
* @oncall relay | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const loadSchema = require('./loadSchema'); | ||
const cosmiconfig = require('cosmiconfig'); | ||
|
||
function loadConfig(folder?: string): any | void { | ||
const schema = loadSchema(); | ||
|
||
const result = cosmiconfig('relay', { | ||
searchPlaces: ['relay.config.js', 'relay.config.json', 'package.json'], | ||
}).searchSync(folder); | ||
if (!result) { | ||
return; | ||
} | ||
const {config, filepath} = result; | ||
|
||
schema.validateObject(config, filepath); | ||
return config; | ||
} | ||
|
||
module.exports = loadConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
* @format | ||
* @oncall relay | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const {JsonSchema} = require('@rushstack/node-core-library'); | ||
const path = require('path'); | ||
|
||
function loadSchema(): any { | ||
return JsonSchema.fromFile( | ||
path.join(__dirname, 'relay-compiler-config-schema.json'), | ||
{ | ||
customFormats: { | ||
uint8: { | ||
type: 'number', | ||
validate: data => data >= 0 && data <= 255, | ||
}, | ||
uint: { | ||
type: 'number', | ||
validate: data => data >= 0 && data <= Number.MAX_SAFE_INTEGER, | ||
}, | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
module.exports = loadSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "relay-config", | ||
"description": "A utility library for loading and saving Relay compiler config files.", | ||
"version": "17.0.0", | ||
"keywords": [ | ||
"graphql", | ||
"relay" | ||
], | ||
"license": "MIT", | ||
"homepage": "https://relay.dev", | ||
"bugs": "https://github.com/facebook/relay/issues", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/facebook/relay.git", | ||
"directory": "packages/relay-config" | ||
}, | ||
"dependencies": { | ||
"@rushstack/node-core-library": "^5.8.0", | ||
"cosmiconfig": "^5.0.5" | ||
}, | ||
"directories": { | ||
"": "./" | ||
}, | ||
"main": "index.js", | ||
"types": "index.d.ts" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we actually use this to generate typescript types, or just for json-schema runtime validation?
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.
using in a gulp task in the build to automatically generate from the schema file so we don't need to manually keep the two in sync