Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const cacheHit = schemaCache[JSON.stringify(optionGroup)];
if (cacheHit && env !== "literal") {
return cacheHit;
}
// Validate and unpack schema
let schema;
if (schemaJson) {
schema = initSchema(schemaJson);
} else if (schemaJsonFilepath) {
schema = initSchemaFromFile(schemaJsonFilepath);
} else if (schemaString) {
schema = initSchemaFromString(schemaString);
} else {
try {
const config = getGraphQLConfig(path.dirname(context.getFilename()));
let projectConfig;
if (projectName) {
projectConfig = config.getProjects()[projectName];
if (!projectConfig) {
throw new Error(
`Project with name "${projectName}" not found in ${config.configPath}.`
);
}
} else {
projectConfig = config.getConfigForFile(context.getFilename());
}
if (projectConfig) {
const key = `${config.configPath}[${projectConfig.projectName}]`;
schema = projectCache[key];
if (!schema) {
schema = projectConfig.getSchema();
export default function loadSchema(
projectName: string,
resolvers: IResolvers,
resolverValidationOptions?: IResolverValidationOptions
) {
// Load the configuration from the provided `.graphqlconfig` file.
const config = getGraphQLProjectConfig(__dirname, projectName);
// Get the GraphQLSchema from the configuration.
const schema = config.getSchema();
// Attach the resolvers to the schema.
addResolveFunctionsToSchema({ schema, resolvers, resolverValidationOptions });
return schema;
}
if (input.cwd) {
// use the endpoint as an alternative, only log the error
try {
configPath = findUp.sync(['.graphqlconfig', '.graphqlconfig.yml'], {
cwd: input.cwd,
})
configString = configPath
? fs.readFileSync(configPath, 'utf-8')
: undefined
folderName = configPath
? path.basename(path.dirname(configPath))
: undefined
try {
const rawConfig = getGraphQLConfig(input.cwd).config
const resolvedConfig = resolveEnvsInValues(rawConfig, input.env)
config = await patchEndpointsToConfigData(
resolvedConfig,
input.cwd,
input.env,
)
config = await patchPrismaEndpointsToConfigData(
resolvedConfig,
input.cwd,
input.env,
)
} catch (e) {
const ymlPath = path.join(input.cwd, 'prisma.yml')
if (!fs.existsSync(ymlPath)) {
throw e
}
config = (await makeConfigFromPath(input.cwd, input.env)).config
const configString = fs.readFileSync(configPath, 'utf-8')
/* tslint:disable-next-line */
// if (configString.includes('${env:')) {
// errify(`You opened a .graphqlconfig file that includes environment variables.
// In order to use environment variables in the Playground, please start it from the graphql cli. Install with
// npm install -g graphql-cli
// Then open the graphql config with:
// cd ${folderPath}; graphql playground`)
// }
const configDir = path.dirname(configPath)
let config
try {
config = await patchEndpointsToConfigData(
resolveEnvsInValues(getGraphQLConfig(configDir).config, env),
configDir,
env,
)
config = await patchPrismaEndpointsToConfigData(
resolveEnvsInValues(getGraphQLConfig(configDir).config, env),
configDir,
env,
)
} catch (e) {
const ymlPath = path.join(configDir, 'prisma.yml')
if (!fs.existsSync(ymlPath)) {
throw e
}
config = await makeConfigFromPath(configDir)
}
// In order to use environment variables in the Playground, please start it from the graphql cli. Install with
// npm install -g graphql-cli
// Then open the graphql config with:
// cd ${folderPath}; graphql playground`)
// }
const configDir = path.dirname(configPath)
let config
try {
config = await patchEndpointsToConfigData(
resolveEnvsInValues(getGraphQLConfig(configDir).config, env),
configDir,
env,
)
config = await patchPrismaEndpointsToConfigData(
resolveEnvsInValues(getGraphQLConfig(configDir).config, env),
configDir,
env,
)
} catch (e) {
const ymlPath = path.join(configDir, 'prisma.yml')
if (!fs.existsSync(ymlPath)) {
throw e
}
config = await makeConfigFromPath(configDir)
}
ipcRenderer.send(
'cwd',
JSON.stringify({ cwd: configDir, id: remote.getCurrentWindow().id }),
)
const state = {
async function start() {
const app = express();
app.use(cors());
app.get('/health', (req, res) => res.sendStatus(200));
const config = await loadConfig({
extensions: [() => ({ name: 'generate' })]
});
const generateConfig = await config!.getDefault().extension('generate');
// connect to db
const db = await connect(generateConfig.db.dbConfig);
const schema = makeExecutableSchema({
typeDefs,
resolvers,
resolverValidationOptions: {
requireResolversForResolveType: false
}
});
// Validate and unpack schema
var schema = void 0;
if (schemaJson) {
schema = initSchema(schemaJson);
} else if (schemaJsonFilepath) {
schema = initSchemaFromFile(schemaJsonFilepath);
} else if (schemaString) {
schema = initSchemaFromString(schemaString);
} else {
try {
var config = (0, _graphqlConfig.getGraphQLProjectConfig)('.', projectName);
schema = config.getSchema();
} catch (e) {
if (e instanceof _graphqlConfig.ConfigNotFoundError) {
throw new Error('Must provide .graphqlconfig file or pass in `schemaJson` option ' + 'with schema object or `schemaJsonFilepath` with absolute path to the json file.');
}
throw e;
}
}
// Validate env
if (env && env !== 'lokka' && env !== 'relay' && env !== 'apollo' && env !== 'literal') {
throw new Error('Invalid option for env, only `apollo`, `lokka`, `relay`, and `literal` supported.');
}
// Validate tagName and set default
var tagName = void 0;
if (tagNameOption) {
tagName = tagNameOption;
} else if (env === 'relay') {
handleSelectFolder = async (folderPath: string) => {
try {
// Get config from folderPath
const envPath = path.join(folderPath, '.env')
let env = process.env
if (fs.existsSync(envPath)) {
const envString = fs.readFileSync(envPath)
const localEnv = dotenv.parse(envString)
if (localEnv) {
env = merge(env, localEnv)
}
}
const configPath = findGraphQLConfigFile(folderPath)
const configString = fs.readFileSync(configPath, 'utf-8')
/* tslint:disable-next-line */
// if (configString.includes('${env:')) {
// errify(`You opened a .graphqlconfig file that includes environment variables.
// In order to use environment variables in the Playground, please start it from the graphql cli. Install with
// npm install -g graphql-cli
// Then open the graphql config with:
// cd ${folderPath}; graphql playground`)
// }
const configDir = path.dirname(configPath)
let config
try {
config = await patchEndpointsToConfigData(
resolveEnvsInValues(getGraphQLConfig(configDir).config, env),
let config: GraphQLProjectConfig | undefined
while (!config) {
try {
config = argv['project']
? getGraphQLProjectConfig(process.cwd(), argv['project'])
: (getGraphQLProjectConfig(process.cwd()) as GraphQLProjectConfig)
config.config = resolveEnvsInValues(config.config, process.env)
config = await patchGraphcoolEndpointsToConfig(
config,
process.cwd(),
)
config = await patchPrismaEndpointsToConfig(config, process.cwd())
config = await patchOpenApiEndpointsToConfig(config)
} catch (error) {
const config: GraphQLConfig = getGraphQLConfig(process.cwd())
const projectNames = Object.keys(config.getProjects() || {})
if (projectNames) {
if (error.message.includes('multiproject')) {
console.log(chalk.yellow('No project name specified'))
} else if (error.message.includes('not a valid project name')) {
console.log(chalk.yellow('Invalid project name specified'))
}
const { projectName } = await inquirer.prompt<{
projectName: string
}>({
type: 'list',
name: 'projectName',
choices: projectNames,
message: 'Select a project:',
})
argv['project'] = projectName
async getProjectConfig() {
let config: GraphQLProjectConfig | undefined
while (!config) {
try {
config = argv['project']
? getGraphQLProjectConfig(process.cwd(), argv['project'])
: (getGraphQLProjectConfig(process.cwd()) as GraphQLProjectConfig)
config.config = resolveEnvsInValues(config.config, process.env)
config = await patchGraphcoolEndpointsToConfig(
config,
process.cwd(),
)
config = await patchPrismaEndpointsToConfig(config, process.cwd())
config = await patchOpenApiEndpointsToConfig(config)
} catch (error) {
const config: GraphQLConfig = getGraphQLConfig(process.cwd())
const projectNames = Object.keys(config.getProjects() || {})
if (projectNames) {
if (error.message.includes('multiproject')) {
console.log(chalk.yellow('No project name specified'))
} else if (error.message.includes('not a valid project name')) {
console.log(chalk.yellow('Invalid project name specified'))