Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useMutation still appears #1162

Closed
wengergruppe opened this issue Jan 18, 2024 · 9 comments · Fixed by #1209
Closed

useMutation still appears #1162

wengergruppe opened this issue Jan 18, 2024 · 9 comments · Fixed by #1209
Assignees
Labels
bug Something isn't working
Milestone

Comments

@wengergruppe
Copy link

wengergruppe commented Jan 18, 2024

What are the steps to reproduce this issue?

Cannot redeclare block-scoped variable

What happens?

UseMutation remains in code despite useMutation: false for this operation Id

What were you expecting to happen?

Any logs, error output, etc?

config:

generateOrval({

  input: {

    target: path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../swagger.json"),

    override: {

      transformer: (inputSchema) => {

        return {

          ...inputSchema,

        

          components: {

            ...inputSchema.components,

            schemas: Object.entries(inputSchema.components?.schemas ?? {}).reduce(

              (acc, [schemaName, schema]) => ({

                ...acc,

                [schemaName]: {

                  ...schema,

                  required: "properties" in schema ? Object.keys(schema.properties ?? {}) : schema

                }

              }),

              {}

            )

          }

        }

      }

   }

  },

 

  output: {

    target: path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../src/openapi/orval"),

    mode: "tags",

    client: "react-query",

    clean: true,

 

    override: {

 

 

      transformer: (verbOptions) => {

        verbOptions.override.operations[verbOptions.operationId] = {

          ...verbOptions.override.operations[verbOptions.operationId],

          query: {

            ...verbOptions.override.operations[verbOptions.operationId]?.query,

            useQuery: true

          }

        }

        return verbOptions

      },

 

      operations: {

        PostLimitRestrictionsRestrictionBreach: {

          query: {

            useQuery: true,

            useMutation: false

          }

        }

      }

    }

  }

})
export const postLimitRestrictionsRestriction = (

    restrictionRequest: RestrictionRequest, options?: AxiosRequestConfig

): Promise<AxiosResponse<Restriction[]>> => {

   

    return [axios.post](http://axios.post/)(

      `/LimitRestrictions/Restriction`,

      restrictionRequest,options

    );

  }

 

 

export const getPostLimitRestrictionsRestrictionQueryKey = (restrictionRequest: RestrictionRequest,) => {

    return [`/LimitRestrictions/Restriction`, restrictionRequest] as const;

    }

 

   

export const getPostLimitRestrictionsRestrictionQueryOptions = <TData = Awaited<ReturnType<typeof postLimitRestrictionsRestriction>>, TError = AxiosError<unknown>>(restrictionRequest: RestrictionRequest, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof postLimitRestrictionsRestriction>>, TError, TData>, axios?: AxiosRequestConfig}

) => {

 

const {query: queryOptions, axios: axiosOptions} = options ?? {};

 

  const queryKey =  queryOptions?.queryKey ?? getPostLimitRestrictionsRestrictionQueryKey(restrictionRequest);

 

 

 

    const queryFn: QueryFunction<Awaited<ReturnType<typeof postLimitRestrictionsRestriction>>> = ({ signal }) => postLimitRestrictionsRestriction(restrictionRequest, { signal, ...axiosOptions });

 

     

 

     

 

   return  { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof postLimitRestrictionsRestriction>>, TError, TData> & { queryKey: QueryKey }

}

 

export type PostLimitRestrictionsRestrictionQueryResult = NonNullable<Awaited<ReturnType<typeof postLimitRestrictionsRestriction>>>

export type PostLimitRestrictionsRestrictionQueryError = AxiosError<unknown>

 

export const usePostLimitRestrictionsRestriction = <TData = Awaited<ReturnType<typeof postLimitRestrictionsRestriction>>, TError = AxiosError<unknown>>(

restrictionRequest: RestrictionRequest, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof postLimitRestrictionsRestriction>>, TError, TData>, axios?: AxiosRequestConfig}

 

  ):  UseQueryResult<TData, TError> & { queryKey: QueryKey } => {

 

  const queryOptions = getPostLimitRestrictionsRestrictionQueryOptions(restrictionRequest,options)

 

  const query = useQuery(queryOptions) as  UseQueryResult<TData, TError> & { queryKey: QueryKey };

 

  query.queryKey = queryOptions.queryKey ;

 

  return query;

}

 

 

 

 

export const getPostLimitRestrictionsRestrictionMutationOptions = <TError = AxiosError<unknown>,

    TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postLimitRestrictionsRestriction>>, TError,{data: RestrictionRequest}, TContext>, axios?: AxiosRequestConfig}

): UseMutationOptions<Awaited<ReturnType<typeof postLimitRestrictionsRestriction>>, TError,{data: RestrictionRequest}, TContext> => {

const {mutation: mutationOptions, axios: axiosOptions} = options ?? {};

 

     

 

 

      const mutationFn: MutationFunction<Awaited<ReturnType<typeof postLimitRestrictionsRestriction>>, {data: RestrictionRequest}> = (props) => {

          const {data} = props ?? {};

 

          return  postLimitRestrictionsRestriction(data,axiosOptions)

        }

 

       

 

 

   return  { mutationFn, ...mutationOptions }}

 

    export type PostLimitRestrictionsRestrictionMutationResult = NonNullable<Awaited<ReturnType<typeof postLimitRestrictionsRestriction>>>

    export type PostLimitRestrictionsRestrictionMutationBody = RestrictionRequest

    export type PostLimitRestrictionsRestrictionMutationError = AxiosError<unknown>

 

    export const usePostLimitRestrictionsRestriction = <TError = AxiosError<unknown>,

    TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postLimitRestrictionsRestriction>>, TError,{data: RestrictionRequest}, TContext>, axios?: AxiosRequestConfig}

) => {

 

      const mutationOptions = getPostLimitRestrictionsRestrictionMutationOptions(options);

 

      return useMutation(mutationOptions);

    }

    export const postLimitRestrictionsRestrictionBreach = (

    restrictionRequest: RestrictionRequest, options?: AxiosRequestConfig

): Promise<AxiosResponse<RestrictionBreach[]>> => {

   

    return [axios.post](http://axios.post/)(

      `/LimitRestrictions/RestrictionBreach`,

      restrictionRequest,options

    );

  }

Any other comments?

What versions are you using?

6.23.0

@melloware melloware added the needs_reproducer Needs a reproducer to prove the issue label Jan 18, 2024
@melloware
Copy link
Collaborator

Providing a runnable reproducer would be ideal.

@thulstrup
Copy link

I have the same problem.

useQuery: true works as expected in v6.15.0 but in v6.16.0 and newer both a useQuery and a useMutation hook is created.

v6.16.0 introduced useMutation options so I guess the problem is somehow related to that.

@thulstrup
Copy link

I did a bit more investigation.

This configuration generates both a mutation and a query function:

override: {
  operations: {
    MyPostOperation: {
      query: {
        useQuery: true,
        useMutation: false,
      }
    }
  }
}

This only generates a query function:

override: {
  query: {
    useMutation: false,
  },
  operations: {
    MyPostOperation: {
      query: {
        useQuery: true,
      },
    }
  }
}

@melloware
Copy link
Collaborator

it must be a bug in this logic here...

  const isMutation =
    (verb !== Verbs.GET && override.query.useMutation) ||
    operationQueryOptions?.useMutation;

@melloware melloware added bug Something isn't working and removed needs_reproducer Needs a reproducer to prove the issue labels Feb 7, 2024
@melloware melloware added this to the 6.25.0 milestone Feb 7, 2024
@thulstrup
Copy link

That did the trick for me 👍

@melloware
Copy link
Collaborator

Oh you tested my PR?

@melloware melloware self-assigned this Feb 7, 2024
@thulstrup
Copy link

Yes, I did.

@melloware
Copy link
Collaborator

Awesome it will be in 6.0.25

@thulstrup
Copy link

Thank you for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants