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

Error: Network error: Network request failed in my React-Native project #45

Closed
gHashTag opened this issue Dec 1, 2017 · 1 comment
Closed

Comments

@gHashTag
Copy link

gHashTag commented Dec 1, 2017

Why do I get this error?
Error: Network error: Network request failed

My store

export const client = new ApolloClient({
  link: createUploadLink({ uri: 'http://localhost:3030/graphql' }),
  cache: new InMemoryCache()
})
const middlewares = [client.middleware(), thunk]
export const store = createStore(
  reducers(client),
  undefined,
  composeWithDevTools(applyMiddleware(...middlewares)),
)

My backend here

My mutation:

export default gql`
  mutation($file: Upload!) {
    uploadFile(file: $file)
  }
`

My action:

  _onShowSignupPress = async () => {
    const { profilePhotoUri } = this.state
    const file = new ReactNativeFile({
      uri: profilePhotoUri,
      type: 'image/jpeg',
      name: 'photo.jpg'
    })
    const response = await this.props.mutate({ variables: { file } })
    console.log(response)
  }

after APOLLO_MUTATION_INIT - APOLLO_MUTATION_ERROR

{
  type: 'APOLLO_MUTATION_INIT',
  mutationString: 'mutation ($file: Upload!) {\n  uploadFile(file: $file)\n}\n',
  mutation: {
    kind: 'Document',
    definitions: [
      {
        kind: 'OperationDefinition',
        operation: 'mutation',
        variableDefinitions: [
          {
            kind: 'VariableDefinition',
            variable: {
              kind: 'Variable',
              name: {
                kind: 'Name',
                value: 'file'
              }
            },
            type: {
              kind: 'NonNullType',
              type: {
                kind: 'NamedType',
                name: {
                  kind: 'Name',
                  value: 'Upload'
                }
              }
            },
            defaultValue: null
          }
        ],
        directives: [],
        selectionSet: {
          kind: 'SelectionSet',
          selections: [
            {
              kind: 'Field',
              alias: null,
              name: {
                kind: 'Name',
                value: 'uploadFile'
              },
              arguments: [
                {
                  kind: 'Argument',
                  name: {
                    kind: 'Name',
                    value: 'file'
                  },
                  value: {
                    kind: 'Variable',
                    name: {
                      kind: 'Name',
                      value: 'file'
                    }
                  }
                }
              ],
              directives: [],
              selectionSet: null
            }
          ]
        }
      }
    ],
    loc: {
      start: 0,
      end: 62,
      source: {
        body: '\n  mutation($file: Upload!) {\n    uploadFile(file: $file)\n  }\n',
        name: 'GraphQL request',
        locationOffset: {
          line: 1,
          column: 1
        }
      }
    }
  },
  variables: {
    file: {
      uri: 'file:///Users/xyz/Library/Developer/CoreSimulator/Devices/BF0FFACC-B049-403D-A27C-048B9BC54636/data/Containers/Data/Application/BCB8B96B-DC71-4ECC-8537-6E4174F78420/Documents/images/F2FDA5B9-B427-476F-BFA7-7FA8E2F8FF10.jpg',
      type: 'image/jpeg',
      name: 'photo.jpg'
    }
  },
  operationName: null,
  mutationId: '1',
  extraReducers: [],
  updateQueries: {}
}

But my server is working
2017-12-01 20 28 17

@gHashTag
Copy link
Author

gHashTag commented Dec 1, 2017

In the Apollo Client 2.0 version they removed the internal dependency on redux, so i won't be able to using the client.middleware anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant