Hi I have problem with passing arguments to query....
# graphql-nexus
p
Hi I have problem with passing arguments to query. I have that query
Copy code
export type input = keyof QueryGetBtsArgs;

const getBts = async (_, arg) => {
  const variables = {
    ...arg,
  };

  const data = await client(
    endpoint,
    gql`
      query getBts($input: input) {
        getBts(input: $input) {
          province {
            name
          }
          provider {
            name
          }
          location {
            name
          }
        }
      }
    `,
    variables,
  );

  return data;
};
and my type QueryGetBtsArgs looks like this:
Copy code
export type QueryGetBtsArgs = {
  minLat?: Maybe<Scalars['Float']>;
  maxLat?: Maybe<Scalars['Float']>;
  minLong?: Maybe<Scalars['Float']>;
  maxLong?: Maybe<Scalars['Float']>;
  providers?: Maybe<Array<Maybe<ProviderEnum>>>;
  technologies?: Maybe<Array<Maybe<TechnologyEnum>>>;
  frequencies?: Maybe<Array<Maybe<FrequencyEnum>>>;
  province?: Maybe<ProvinceEnum>;
  location?: Maybe<Scalars['String']>;
  skip?: Maybe<Scalars['Int']>;
};
I have error
Copy code
Error: Unknown type "input". Did you mean "Int"?: {"response":{"errors":[{"message":"Unknown type \"input\". Did you mean \"Int\"?","locations":[{"line":2,"column":28}],"
how I should extend this args from QueryGetBtsArgs and pass it to query? Thanks for help 😉
r
Hey @Peter 👋 The type here seems incorrect:
Copy code
query getBts($input: input) {
What is the type you see in the GraphQL Playground? You would need to add that here instead of
input
as that is not a type declared anywhere.
p
a don’t have any types just args
so how I could add all props from type QueryGetBtsArgs?
I whant to use types generated from graphql-codegen
r
Could you share what this query looks like in the Playground?
p
r
In this case, you would need to pass the inputs separately as this requires separate parameters. Something like this:
Copy code
query getBts(
  $minLat: Int
  $maxLat: Int
  $minLong: Float
  $maxLong: Float
 ... and so on
) {
}
p
Yes sure but it is possible to don’t write all args and just pass somehow the generated type?
r
You would need to create the type in the backend to pass all the args in that form. GraphQL Codegen provides you with TypeScript types but you would need to write the arguments in the query yourself.
p
and it will be https://nexusjs.org/docs/api/input-object-type or what exac type?
I can’t see on docs how I should pass to args any type 😕
even I do that I will also need pass each argument in query?