Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return props.client.query({ query: introspectionQuery }).then(result => {
if (result.errors) {
// tslint:disable-next-line no-console
console.log(`Unable to fetch GraphQL schema: ${result.errors}`);
return null;
} else {
const schema = fromIntrospectionQuery(result.data) as JSONSchema7;
// FIXME: update "graphql-2-json-schema" to generate JSONSchema7
schema.$schema = 'http://json-schema.org/draft-07/schema#';
return {
schema: schemaWithFormats(buildFormSchema(schema, mutationName), props.formats || {}),
mutationName
};
}
});
} else {
// ------
console.log('[2/3] generate mutations enum type ...');
const mutationNames = extractMutationsNamesFromFile(path.resolve(outputPath, 'schema.json'));
if (mutationNames) {
fs.writeFileSync(
path.resolve(outputPath, 'mutations.d.ts'),
generateMutationTypesDef(mutationNames)
);
} else {
console.error('Failed to generate mutations typing');
}
// ------
console.log('[3/3] generate json schema file ...');
const jsonSchemaObj = fromIntrospectionQuery(
JSON.parse(fs.readFileSync(path.resolve(outputPath, 'schema.json')).toString()).data
);
fs.writeFileSync(
path.resolve(outputPath, 'apollo-form-json-schema.json'),
JSON.stringify(jsonSchemaObj)
);
} catch (error) {
console.error(error);
}
console.log('Done.');
}
)
import { fromIntrospectionQuery } from 'graphql-2-json-schema';
import gql from 'graphql-tag';
import { JSONSchema6 } from 'json-schema';
import { keys } from 'lodash';
import * as React from 'react';
import { ApolloConsumer } from 'react-apollo';
import { FieldProps } from 'react-jsonschema-form';
import { schema as mockSchema } from '../graphql-mock';
import { configure, ApolloFormConfigureTheme } from '../lib/forms/component';
import { ErrorListComponent } from '../lib/forms/renderers';
import { ReactJsonschemaFormError } from '../lib/forms/utils';
const { Button, Input, Checkbox, Header, Form, Message } = require('semantic-ui-react');
const { withKnobs, select, boolean: bool } = require('@storybook/addon-knobs/react');
const introspection = graphqlSync(mockSchema, introspectionQuery).data as IntrospectionQuery;
const jsonSchema = fromIntrospectionQuery(introspection);
const document = gql`
mutation createTodo($todo: TodoInputType!) {
create_todo(todo: $todo) {
id
}
}
`;
const ErrorList: ErrorListComponent = p => (
e.message)}
/>
);