Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
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'))
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')) {
function tryGetGraphQLProjectConfig() {
try {
return getGraphQLProjectConfig()
} catch (error) {
if (error.name === 'ConfigNotFoundError') {
return {}
} else {
throw error
}
}
}
export const validateCliOptions = (options: CLIOptions) => {
const schema = options.schema;
const template = options.template;
const project = options.project;
if (!schema && isNode) {
const { getGraphQLProjectConfig, ConfigNotFoundError } = require('graphql-config');
try {
const graphqlProjectConfig = getGraphQLProjectConfig(project);
options.schema = graphqlProjectConfig.schemaPath;
} catch (e) {
if (e instanceof ConfigNotFoundError) {
cliError('Flag --schema is missing!');
}
}
}
if (!template && !project) {
cliError('Please specify language/platform, using --template flag!');
}
};