Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
generate: ({
serverUrl,
variableName,
operationType,
operationName,
operation,
options,
}) => {
// snippet here
return refmt.printRE(
refmt.parseRE(`
let serverUrl = "${serverUrl}"
let ${variableName} = [%graphql
{|
${operation}
|}
]
let payload = Js.Dict.empty();
Js.Dict.set(payload, "${operationType}", Js.Json.string(${variableName}));
Js.Promise.(
Fetch.fetch(serverUrl,
Fetch.RequestInit.make(
~method_=Post,
generate: ({
appId,
variableName,
operationType,
operationName,
operation,
options,
}) => {
// snippet here
return refmt.printRE(
refmt.parseRE(`type schoolPerson = Teacher | Director | Student(string);
let greeting = person =>
switch (person) {
| Teacher => "Hey Professor!"
| Director => "Hello Director."
| Student("Richard") => "Still here Ricky?"
| Student(anyOtherName) => "Hey, " ++ anyOtherName ++ "."
};`),
);
},
};
export function format(code: string) {
try {
return refmt.printRE(refmt.parseRE(code))
} catch (e) {
console.log(
`There is a syntax error in generated code, unformatted code printed, error: ${JSON.stringify(
e,
)}`,
)
return code
}
}
export const refmt = (str: string) => printRE(parseRE(str));
const refmt = (str: string) => printRE(parseRE(str));
const apolloClient = options.client
? `
let inMemoryCache = ApolloInMemoryCache.createInMemoryCache();
let serverUrl = "${serverUrl}"
let httpLink =
ApolloLinks.createHttpLink(~uri=serverUrl, ());
let instance =
ReasonApollo.createApolloClient(~link=httpLink, ~cache=inMemoryCache, ());
`
: '';
return refmt.printRE(
refmt.parseRE(`
${apolloClient}
module ${queryName} = [%graphql
{|
${operation}
|}
];
module ${componentName} = ReasonApollo.CreateQuery(${queryName});
let make = _children => {
render: _ => {
${options.client ? '' : ''}
<${componentName}>
...{