| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import { constantCase, pascalCase } from 'change-case';
- import { NewPluginTemplateContext } from '../../types';
- export function renderApiExtensions(context: NewPluginTemplateContext) {
- if (!context.withApiExtensions) {
- return '';
- }
- if (!context.withCustomEntity) {
- return /* language=TypeScript */ `
- import gql from 'graphql-tag';
- export const shopApiExtensions = gql\`
- extend type Query {
- exampleShopQuery: String!
- }
- extend type Mutation {
- exampleShopMutation(input: String!): String!
- }
- \`;
- export const adminApiExtensions = gql\`
- extend type Query {
- exampleAdminQuery: String!
- }
- extend type Mutation {
- exampleAdminMutation(input: String!): String!
- }
- \`;
- `;
- } else {
- const entityName = context.entity.className;
- return /* language=TypeScript */ `
- import gql from 'graphql-tag';
- export const commonApiExtensions = gql\`
- type ${entityName} implements Node {
- id: ID!
- createdAt: DateTime!
- updatedAt: DateTime!
- name: String!
- }
- type ${entityName}List implements PaginatedList {
- items: [${entityName}!]!
- totalItems: Int!
- }
- extend type Query {
- ${context.entity.instanceName}s(options: ${entityName}ListOptions): ${entityName}List!
- ${context.entity.instanceName}(id: ID!): ${entityName}
- }
- # Auto-generated at runtime
- input ${entityName}ListOptions
- \`;
- export const shopApiExtensions = gql\`
- \${commonApiExtensions}
- \`;
- export const adminApiExtensions = gql\`
- \${commonApiExtensions}
- extend type Mutation {
- create${entityName}(input: Create${entityName}Input!): ${entityName}!
- update${entityName}(input: Update${entityName}Input!): ${entityName}!
- }
- input Create${entityName}Input {
- name: String!
- }
- input Update${entityName}Input {
- id: ID!
- name: String!
- }
- \`;
- `;
- }
- }
|