Skip to content

Create a service by .graphql with all operations in Angular #8792

Discussion options

You must be logged in to vote

I create a custom plugin

module.exports = {

  plugin(schema: any, documents: any, config: any) {

    let code = ``

    documents.forEach(doc => {
      let name = createName(doc.location)
      code += `
    @Injectable({
      providedIn: "root"
    })
    export class ${name}Service {
       constructor(
        ${doc.document.definitions.map(d => `  private _${uncapitalize(d.name.value)}: ${d.name.value}GQL`).join(",\n        ")}
       ) {
       }
       \n`;

      code += doc.document.definitions
        .filter(d => d.operation == 'query')
        .map(d => query(d))
        .join("\n")

      code += doc.document.definitions
        .filter(d => d.operation == 'mutation')

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@MiguelAngelLV
Comment options

@saihaj
Comment options

saihaj Jan 5, 2023
Collaborator

Comment options

You must be logged in to vote
0 replies
Answer selected by MiguelAngelLV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants